I have this code written:
return Host.CreateDefaultBuilder()
.UseSerilog((context, services, configuration) => configuration
.MinimumLevel.Verbose()
.ReadFrom.Configuration(_configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.Enrich.With(UserLoginEnricher.GetInstance())
.Enrich.With(new LoggersAdditionalEnricher())
//CSV logger
.WriteTo.Logger(x =>
{
x.WriteTo.File(ApplicationConfiguration.FullPathToCsvFile,
rollingInterval: RollingInterval.Day,
encoding: Encoding.Unicode,
retainedFileCountLimit: ApplicationConfiguration.AppSettingsOptions.RetainDataCount,
outputTemplate: "{Message}{NewLine}");
//log filter
x.Filter.ByIncludingOnly(e =>
{
if (!e.Properties.ContainsKey(nameof(LogType)))
return false;
return e.Properties[nameof(LogType)].ToString() == LogType.CSV.ToString();
});
})
.WriteTo(x =>{...})
.WriteTo(x =>{...});
Is there any way to configure json SERILOG configuration to change minimum level of File logger without code changes?
My JSON config of serilog:
"Serilog": {
"Using": [
"Serilog.Sinks.File"
],
"MinimumLevel": {
"Default": "Verbose",
"Override": {
"Microsoft": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
}
}
}
I have more loggers. I need all loggers to write with Warning level and this CSV logger to write on Information level
UPD:
The problem: I have many 'WriteTo's which write to files. They all are written in code. I need to make one logger to write to level 1, and others to another level WITHOUT code changes.
I guess i cannot rewrite these loggers with json configuration, because these loggers generate file name from machine name, current windows username, logfile type and date:
(ex. [RU-PF10PUV1][Vlad.Pupkin][CalendarCollector_OutlookCalendarLog][_20220921.csv)
Is this right?
Also i need to know is it possible to somehow override existing code configuration with json config. Something like
"Override":
{
"Utility.Logging.LogType.CSV": "Information"// LogType.CSV is a property of logged message
}
Is there any way to solve this problem