Serilog : Log to different files

后端 未结 3 2286
广开言路
广开言路 2021-02-18 17:38

I am logging events of all types to single Json file irrespective of LogLevel. Now I have a requirement to log some custom performance counters to a seperate Json file. How can

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-18 18:01

    If you want to have an independent logging pipeline, just make another instance. This is robbed and adapted from https://github.com/serilog/serilog/wiki/Lifecycle-of-Loggers:

    using (var performanceCounters = new LoggerConfiguration()
            .WriteTo.File(@"myapp\log.txt")
            .CreateLogger())
    {
        performanceCounters.Information("Performance is really good today ;-)");
    
        // Your app runs, then disposal of `performanceCounters` flushes any buffers
    }
    

提交回复
热议问题