Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET - Serilog - Multiple sinks each one for a different use

I want to use Serilog for logging because I worked with it and it fits my needs.

The difference in this case is that I need to log different modules and I would like each module to be logged in a different folder and even maybe in a different sink.

I am not talking about using several sinks, but I talk about doing something like this:

Serilog.Log(LogInstance1,"Log for module 1") // Logs in a rolling text file in folder X 10 files of 1MB each
Serilog.Log(LogInstance2,"Log for module 2") // Logs i na text file that doesn't delete old entries

Does anyone know if this is possible to achieve with Serilog?

like image 399
Asaf Epelbaum Avatar asked May 16 '18 12:05

Asaf Epelbaum


1 Answers

You can make multiple separate ILogger instances, each with their own configuration and set of sinks etc.; each pipeline operates completely separately with no shared state of any kind.

var logger1 = new LoggerConfiguration().
    .WriteTo.File(...10...)
    .CreateLogger();

var logger2 = new LoggerConfiguration()
    .WriteTo.File(...)
    .CreateLogger();

logger1.Information("Log for Module 1");
logger2.Information("Log for Module 2");
like image 144
Ruben Bartelink Avatar answered Oct 26 '22 22:10

Ruben Bartelink