I am trying to implement serilog in a little sample-project. I´ve did the following so far:
- Create new ASP.NET Core Web Application (MVC)
- Install-Package Serilog.AspNetCore
- Install-Package Serilog.Sinks.File
- Install-Package Serilog.Formatting.Compact
- Follow this blogpost
- Try to follow this blogpost
My question:
Is there a possibility to configure two different loggers, based on CategoryName (in my case "MyLogger")? I want this logger to use a different file, than my default-logger. In my happy-world-fantasy it would look like:
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.File(new CompactJsonFormatter(), @"C:\temp\standardLog.txt")
.WriteTo.File(new CompactJsonFormatter(), @"C:\temp\specialLog.txt").Filter.ByIncludingOnly(x => x.SourceContext("MySpecialLogger")
.CreateLogger();
And if I create a new Logger var logger = _loggerFactory.CreateLogger("MySpecialLogger"); the logs will be safed in my specialLog.txt-file.
Any ideas?