From b87eae294670534d2ba2af5c4c8b57b4849b2d39 Mon Sep 17 00:00:00 2001 From: elzik <23397871+elzik@users.noreply.github.com> Date: Sat, 23 Sep 2023 19:48:26 +0100 Subject: [PATCH] Log service to file --- .../Elzik.FmSync.Infrastructure.csproj | 9 ---- Elzik.FmSync.sln | 1 + Elzik.FmSync.sln.DotSettings | 1 + .../Elzik.FmSync.Worker.csproj | 44 ++++++++++++------- src/Elzik.FmSync.Worker/Program.cs | 11 ++++- src/Elzik.FmSync.Worker/appsettings.json | 12 +++++ 6 files changed, 52 insertions(+), 26 deletions(-) delete mode 100644 Elzik.FmSync.Infrastructure/Elzik.FmSync.Infrastructure.csproj diff --git a/Elzik.FmSync.Infrastructure/Elzik.FmSync.Infrastructure.csproj b/Elzik.FmSync.Infrastructure/Elzik.FmSync.Infrastructure.csproj deleted file mode 100644 index cfadb03..0000000 --- a/Elzik.FmSync.Infrastructure/Elzik.FmSync.Infrastructure.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net7.0 - enable - enable - - - diff --git a/Elzik.FmSync.sln b/Elzik.FmSync.sln index 091773c..ebc6a9a 100644 --- a/Elzik.FmSync.sln +++ b/Elzik.FmSync.sln @@ -27,6 +27,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{0FE56BA0-BDDF-4291-9BDD-A6D512610FAE}" ProjectSection(SolutionItems) = preProject Build\continuous-integration.ps1 = Build\continuous-integration.ps1 + Build\local-install.ps1 = Build\local-install.ps1 Build\publish.ps1 = Build\publish.ps1 EndProjectSection EndProject diff --git a/Elzik.FmSync.sln.DotSettings b/Elzik.FmSync.sln.DotSettings index c1aeb36..d32ab99 100644 --- a/Elzik.FmSync.sln.DotSettings +++ b/Elzik.FmSync.sln.DotSettings @@ -1,5 +1,6 @@  True + True True True True diff --git a/src/Elzik.FmSync.Worker/Elzik.FmSync.Worker.csproj b/src/Elzik.FmSync.Worker/Elzik.FmSync.Worker.csproj index 10ca2a7..ed0018d 100644 --- a/src/Elzik.FmSync.Worker/Elzik.FmSync.Worker.csproj +++ b/src/Elzik.FmSync.Worker/Elzik.FmSync.Worker.csproj @@ -1,19 +1,33 @@ - - net7.0 - enable - enable - dotnet-Elzik.FmSync.Worker-4d67e15b-f529-48cc-919a-3c678579aeb2 - Linux - + + net7.0 + enable + enable + dotnet-Elzik.FmSync.Worker-4d67e15b-f529-48cc-919a-3c678579aeb2 + Linux + - - - + + + + + + + + - - - - - + + IS_WINDOWS_OS + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Elzik.FmSync.Worker/Program.cs b/src/Elzik.FmSync.Worker/Program.cs index fe33e27..b381a52 100644 --- a/src/Elzik.FmSync.Worker/Program.cs +++ b/src/Elzik.FmSync.Worker/Program.cs @@ -2,10 +2,13 @@ using Elzik.FmSync.Domain; using Elzik.FmSync.Infrastructure; using Elzik.FmSync.Worker; +using Serilog; using Thinktecture.IO.Adapters; using Thinktecture.IO; var host = Host.CreateDefaultBuilder(args) + .UseSerilog((ctx, lc) => lc + .ReadFrom.Configuration(ctx.Configuration)) .ConfigureServices((hostContext, services) => { services.AddSingleton(); @@ -14,14 +17,18 @@ services.Configure(hostContext.Configuration.GetSection("FmSyncOptions")); services.Configure(hostContext.Configuration.GetSection("FileSystemOptions")); services.Configure(hostContext.Configuration.GetSection("FrontMatterOptions")); +#if IS_WINDOWS_OS + services.AddWindowsService(options => + { + options.ServiceName = "fmsync"; + }); +#endif services.AddHostedService(); }) .ConfigureAppConfiguration((_, config) => { config.AddJsonFile("appSettings.json", true, true); }) - .ConfigureLogging((context, config) => - config.AddConfiguration(context.Configuration.GetSection("Logging"))) .Build(); host.Run(); diff --git a/src/Elzik.FmSync.Worker/appsettings.json b/src/Elzik.FmSync.Worker/appsettings.json index 84fe98a..e945168 100644 --- a/src/Elzik.FmSync.Worker/appsettings.json +++ b/src/Elzik.FmSync.Worker/appsettings.json @@ -12,5 +12,17 @@ }, "FrontMatterOptions": { "TimeZoneId": "" + }, + "Serilog": { + "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { "Name": "Console" }, + { + "Name": "File", + "Args": { "path": "C:\\ProgramData\\fmsync\\Elzik.FmSync.Worker.log" } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], } } \ No newline at end of file