Skip to content

Commit

Permalink
Add file logging to console
Browse files Browse the repository at this point in the history
  • Loading branch information
elzik committed Sep 23, 2023
1 parent 65de49e commit cf6f6a8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
10 changes: 10 additions & 0 deletions src/Elzik.FmSync.Console/Elzik.FmSync.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<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" /> <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.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.10.0.77988">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
3 changes: 3 additions & 0 deletions src/Elzik.FmSync.Console/Presentation/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Thinktecture.IO;
using Thinktecture.IO.Adapters;

var host = Host.CreateDefaultBuilder(args)
.UseSerilog((context, config) => config
.ReadFrom.Configuration(context.Configuration))
.ConfigureServices((context,services) =>
{
services.AddTransient<IMarkdownFrontMatter, MarkdownFrontMatter>();
Expand Down
23 changes: 12 additions & 11 deletions src/Elzik.FmSync.Console/appSettings.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"Logging": {
"LogLevel": {
"Default": "Information"
},
"Console": {
"FormatterName": "Simple",
"FormatterOptions": {
"SingleLine": true
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": { "path": "C:\\ProgramData\\fmsync\\Elzik.FmSync.Console.log" }
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
},
"FrontMatterOptions": {
"TimeZoneId": ""
},
"FileSystemOptions": {
"FilenamePattern": "*.md"
}
"FilenamePattern": "*.md"
}
}
4 changes: 2 additions & 2 deletions src/Elzik.FmSync.Worker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
using Thinktecture.IO;

var host = Host.CreateDefaultBuilder(args)
.UseSerilog((ctx, lc) => lc
.ReadFrom.Configuration(ctx.Configuration))
.UseSerilog((context, config) => config
.ReadFrom.Configuration(context.Configuration))
.ConfigureServices((hostContext, services) =>
{
services.AddSingleton<IMarkdownFrontMatter, MarkdownFrontMatter>();
Expand Down
9 changes: 2 additions & 7 deletions src/Elzik.FmSync.Worker/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"Logging": {
"LogLevel": {
"Default": "Information"
}
},
"FmSyncOptions": {
"WatchedDirectoryPaths": [ "C:\\TempObsidian" ]
},
Expand All @@ -15,14 +10,14 @@
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"MinimumLevel": "Information",
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": { "path": "C:\\ProgramData\\fmsync\\Elzik.FmSync.Worker.log" }
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
}
}

0 comments on commit cf6f6a8

Please sign in to comment.