My company is looking to change from Miscrosoft's Enterprise logging framework to Serilog. I am currently being tasked with changing the logging framework over to Serilog so that it.
Does not change the implementation of any current calls using the our logging class.
Mimics the structure used in our old App.config file so that all of the settings are the same.
I am changing everything over to read from a .json file but I am running into an issue. I need to ensure that someone can go into the appsettings.json file and add a new file to log to.
I.E
"Listeners": {
"File 1": {
"fileName": "C:\\logs\\Warning.txt",
"rollInterval": "Day",
"rollOnFileSizeLimit": true,
"rollSize": 2000,
"filter": "Information"
},
"File 2": {
"fileName": "C:\\logs\\Info.txt",
"rollInterval": "Day",
"rollOnFileSizeLimit": true,
"rollSize": 2000,
"filter": "Error"
}
}
This is my current implementation of the serilog logger. I am currently specifying a path based on the severity level and storing it in "path", but it needs to be changed so that I am specifying potentially an array of paths based on the category.
Serilog.Log.Logger = new LoggerConfiguration()
.Enrich.WithMachineName()
.Enrich.WithThreadId()
.Enrich.WithProcessId()
.MinimumLevel.Information()
.WriteTo.Debug()
.WriteTo.File(
Settings.GetSetting(path, null),
outputTemplate: Settings.GetSetting("Logging:Template", null))
.CreateLogger();
ILogger log = Serilog.Log.ForContext(Enricher.CategoryContext, Category.ToString());
If someone adds a file to the listeners, then it should be able to output a log to it. This also includes outputting to a database. The problem I am facing is that I cannot see a possible way to do this in a single Serilog configuration.
Additionally, I stumbled upon a NuGet package called Serilog.Sinks.Map which does do what I want, but it is in pre-release, and not suitable for my company's production code.