adds basic serilog setup

This commit is contained in:
Philipp Häfelfinger 2023-09-11 22:42:52 +02:00
parent adcf8b1504
commit e6f4ebe4cb
3 changed files with 23 additions and 10 deletions

View File

@ -23,9 +23,12 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" /> <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0"/> <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0"/> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="Piwigo.Client" Version="0.1.0.19" /> <PackageReference Include="Piwigo.Client" Version="0.1.0.19" />
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Spectre.Console.Analyzer" Version="0.47.0"> <PackageReference Include="Spectre.Console.Analyzer" Version="0.47.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@ -6,18 +6,28 @@ using PiwigoDirectorySync.Commands;
using PiwigoDirectorySync.Infrastructure; using PiwigoDirectorySync.Infrastructure;
using PiwigoDirectorySync.Persistence; using PiwigoDirectorySync.Persistence;
using PiwigoDirectorySync.Services; using PiwigoDirectorySync.Services;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
using Spectre.Console.Cli; using Spectre.Console.Cli;
const string outputTemplateConsole = "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}: {Message}";
const string outputTemplateFile = "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message}{NewLine}{NewLine}{Exception}{NewLine}";
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("System", LogEventLevel.Warning)
.MinimumLevel.Override("Piwigo.Client", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Console(LogEventLevel.Warning, outputTemplateConsole, theme: AnsiConsoleTheme.Literate)
.WriteTo.File("logs/PiwigoDirectorySync.txt", LogEventLevel.Debug, outputTemplate:outputTemplateFile, rollingInterval: RollingInterval.Day)
.CreateLogger();
var registrations = new ServiceCollection(); var registrations = new ServiceCollection();
registrations.AddSingleton(AppSettings.Config); registrations.AddSingleton(AppSettings.Config);
registrations.AddLogging(l => l.AddConfiguration(AppSettings.Config.GetSection("Logging")) registrations.AddLogging(l => l.AddConfiguration(AppSettings.Config.GetSection("Logging")).AddSerilog());
.AddSimpleConsole(c =>
{
c.SingleLine = true;
c.IncludeScopes = true;
})
.AddDebug());
registrations.AddTransient<IPiwigoClientFactory, PiwigoClientFactory>(); registrations.AddTransient<IPiwigoClientFactory, PiwigoClientFactory>();
registrations.AddTransient<IFileIndexer, FileIndexer>(); registrations.AddTransient<IFileIndexer, FileIndexer>();

View File

@ -3,7 +3,7 @@
"profiles": { "profiles": {
"ScanLocalJpgs": { "ScanLocalJpgs": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "scan 2", "commandLineArgs": "scan 1",
"environmentVariables": { "environmentVariables": {
} }
}, },