adds basic serilog setup
This commit is contained in:
parent
adcf8b1504
commit
e6f4ebe4cb
@ -23,9 +23,12 @@
|
||||
<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.Json" Version="7.0.0"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="7.0.0" />
|
||||
<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">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
@ -6,18 +6,28 @@ using PiwigoDirectorySync.Commands;
|
||||
using PiwigoDirectorySync.Infrastructure;
|
||||
using PiwigoDirectorySync.Persistence;
|
||||
using PiwigoDirectorySync.Services;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using Serilog.Sinks.SystemConsole.Themes;
|
||||
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();
|
||||
|
||||
registrations.AddSingleton(AppSettings.Config);
|
||||
registrations.AddLogging(l => l.AddConfiguration(AppSettings.Config.GetSection("Logging"))
|
||||
.AddSimpleConsole(c =>
|
||||
{
|
||||
c.SingleLine = true;
|
||||
c.IncludeScopes = true;
|
||||
})
|
||||
.AddDebug());
|
||||
registrations.AddLogging(l => l.AddConfiguration(AppSettings.Config.GetSection("Logging")).AddSerilog());
|
||||
|
||||
registrations.AddTransient<IPiwigoClientFactory, PiwigoClientFactory>();
|
||||
registrations.AddTransient<IFileIndexer, FileIndexer>();
|
||||
|
@ -3,7 +3,7 @@
|
||||
"profiles": {
|
||||
"ScanLocalJpgs": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "scan 2",
|
||||
"commandLineArgs": "scan 1",
|
||||
"environmentVariables": {
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user