Serilog.Sinks.Postgresql: Read configuration from appsettings.json
You can use Serilog.Settings.Configuration
to add your own configuration from there.There is a good example here: github of seriog app-setting
I guess in your case it would look something like:
var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true) .Build(); var logger = new LoggerConfiguration() .ReadFrom.Configuration(configuration) .CreateLogger();
When your config will look something like:
{ "Serilog": { "Using": ["Serilog.Sinks.Postgresql"], "MinimumLevel": "Debug", "WriteTo": [ { "Name": "Console" }, { "Name": "File", "Args": { "path": "%TEMP%\\Logs\\serilog-configuration-sample.txt" } } ], "Enrich": ["FromLogContext", "WithMachineName", "WithThreadId"], "Destructure": [ { "Name": "With", "Args": { "policy": "Sample.CustomPolicy, Sample" } }, { "Name": "ToMaximumDepth", "Args": { "maximumDestructuringDepth": 4 } }, { "Name": "ToMaximumStringLength", "Args": { "maximumStringLength": 100 } }, { "Name": "ToMaximumCollectionCount", "Args": { "maximumCollectionCount": 10 } } ], "Properties": { "Application": "Sample" } }}
You can get more information here gitub of Serilog setting