Skip to content

Commit

Permalink
Log service to file
Browse files Browse the repository at this point in the history
  • Loading branch information
elzik committed Sep 23, 2023
1 parent d26871d commit b87eae2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 26 deletions.

This file was deleted.

1 change: 1 addition & 0 deletions Elzik.FmSync.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Elzik.FmSync.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Elzik/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=fmsync/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Synchronised/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Synchroniser/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Synchronising/@EntryIndexedValue">True</s:Boolean>
Expand Down
44 changes: 29 additions & 15 deletions src/Elzik.FmSync.Worker/Elzik.FmSync.Worker.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-Elzik.FmSync.Worker-4d67e15b-f529-48cc-919a-3c678579aeb2</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-Elzik.FmSync.Worker-4d67e15b-f529-48cc-919a-3c678579aeb2</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Elzik.FmSync.Application\Elzik.FmSync.Application.csproj" />
<ProjectReference Include="..\Elzik.FmSync.Infrastructure\Elzik.FmSync.Infrastructure.csproj" />
</ItemGroup>
</Project>
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<DefineConstants>IS_WINDOWS_OS</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Elzik.FmSync.Application\Elzik.FmSync.Application.csproj" />
<ProjectReference Include="..\Elzik.FmSync.Infrastructure\Elzik.FmSync.Infrastructure.csproj" />
</ItemGroup>

</Project>
11 changes: 9 additions & 2 deletions src/Elzik.FmSync.Worker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IMarkdownFrontMatter, MarkdownFrontMatter>();
Expand All @@ -14,14 +17,18 @@
services.Configure<FmSyncOptions>(hostContext.Configuration.GetSection("FmSyncOptions"));
services.Configure<FileSystemOptions>(hostContext.Configuration.GetSection("FileSystemOptions"));
services.Configure<FrontMatterOptions>(hostContext.Configuration.GetSection("FrontMatterOptions"));
#if IS_WINDOWS_OS
services.AddWindowsService(options =>
{
options.ServiceName = "fmsync";
});
#endif
services.AddHostedService<FmSyncWorker>();
})
.ConfigureAppConfiguration((_, config) =>
{
config.AddJsonFile("appSettings.json", true, true);
})
.ConfigureLogging((context, config) =>
config.AddConfiguration(context.Configuration.GetSection("Logging")))
.Build();

host.Run();
12 changes: 12 additions & 0 deletions src/Elzik.FmSync.Worker/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ],
}
}

0 comments on commit b87eae2

Please sign in to comment.