Split out loggingStart service to its own file and namespace

This commit is contained in:
2022-06-11 21:52:16 +01:00
parent d15571a98d
commit e83cac2838
2 changed files with 37 additions and 39 deletions

View File

@@ -1,25 +1,22 @@
using api.Launch;
using Diary.Data;
using Diary.Installers;
using Serilog;
using Serilog.Events;
using System.Reflection;
using ILogger = Serilog.ILogger;
/*
* Settings - Done by sefaulr
* Logging - Done
* Database - Donw
* Dependencies
* automapper
* automapper - Done
* Cors
* Views/Filters/Validation
* Swagger
* Swagger - Done
* Auth
*
* */
//+Setup Logger
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
@@ -28,6 +25,7 @@ Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.Seq("http://seq.lan:5341", apiKey: "Jtfj82GQmcKTAh1kW3zI")
.WriteTo.File("Logs/Log.txt")
.Enrich.FromLogContext()
.CreateLogger();
try
@@ -44,11 +42,13 @@ try
//---Y
//Database
builder.Services.AddDatabase(builder.Configuration);
builder.Services.AddScoped<IDiaryDBContext, DiaryDBContext>();
//---Y
//Automapper
builder.Services.AddAutoMapper(Assembly.GetExecutingAssembly());
builder.Services.AddControllers();
builder.Services.AddScoped<IDiaryDBContext, DiaryDBContext>();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
@@ -80,9 +80,6 @@ try
app.MapControllers();
app.Run();
}
catch (Exception ex)
{
@@ -92,33 +89,4 @@ finally
{
Log.Information("Shut down complete");
Log.CloseAndFlush();
}
namespace api.Launch
{
public class LoggingStartService : IHostedService
{
private readonly ILogger _log;
private readonly string _serviceName;
public ILogger Logger { get; }
public LoggingStartService(ILogger logger, string serviceName)
{
_log = logger.ForContext<LoggingStartService>();
_serviceName = serviceName ?? "API";
}
public Task StartAsync(CancellationToken cancellationToken)
{
_log.Information("{ServiceName} service started", _serviceName);
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
_log.Information("{ServiceName} service stopped", _serviceName);
return Task.CompletedTask;
}
}
}