I am using serilog in a web api in .net framework with the serilog config added in the Web.Config file as below
<appSettings>
<add key="serilog:minimum-level" value="Information" />
<add key="serilog:using:File" value="Serilog.Sinks.File" />
<add key="serilog:write-to:File.path" value="C:\api\logs\api_log.log" />
<add key="serilog:write-to:File.formatter" value="Serilog.Formatting.Json.JsonFormatter, Serilog" />
<add key="serilog:write-to:File.rollingInterval" value="Day" />
<add key="serilog:write-to:File.fileSizeLimitBytes" value="5242880" />
<add key="serilog:write-to:File.rollOnFileSizeLimit" value="true" />
<add key="serilog:write-to:File.shared" value="true" />
</appSettings>
I have registered the logger in the startup file as below
private static ILogger ConfigureSerilog()
{
IConfigurationRoot configuration = new ConfigurationBuilder()
.Add(new XmlConfigurationProvider())
.Build();
LoggerConfiguration loggerConfiguration = new LoggerConfiguration().Enrich.With(new SerilogClaimValueEnricher())
.Enrich.WithDemystifiedStackTraces()
.ReadFrom.Configuration(configuration);
Logger rootLogger = loggerConfiguration.CreateLogger();
Log.Logger = rootLogger;
return rootLogger;
}
The configuration object is getting all the values that we are given in the web.config but the logging is not working. But instead of ReadFrom.Configuration(configuration)
if I use ReadFrom.AppSettings()
the logging is working corectly. But I need make use of IConfigurationRoot
here. Did I missed anything?
Please not XmlConfigurationProvider
is a custom class to read keys from web.config
Below is the screenshot of debug mode states of the configuration.