0

I was told to ask this here.

I would like Serilog to tell me which class the logging is being done. This is my code to set the serilog:

Logger = new LoggerConfiguration()
                .MinimumLevel.Verbose()
                .WriteTo.Console()
                .Enrich.FromLogContext()
                .CreateLogger();
Justin
  • 11
  • 4
  • Does this answer your question? [How to enable Serilog minimum level overrides without particular convention of calling ForContext?](https://stackoverflow.com/questions/61391392/how-to-enable-serilog-minimum-level-overrides-without-particular-convention-of-c) – C. Augusto Proiete Feb 08 '21 at 20:59
  • I believe you are looking for [Serilog Source Contexts](https://github.com/serilog/serilog/wiki/Writing-Log-Events#source-contexts) – C. Augusto Proiete Feb 08 '21 at 21:03
  • These are both correct. But is seems I need to do DI since I would like to use it everywhere – Justin Feb 08 '21 at 21:31
  • 1
    The simplest way (and my personal preference) is to use declare an `ILogger` member variable on each class, and use the ambient `Log.ForContext` to get the logger for the specific class context. https://stackoverflow.com/a/61413261 – C. Augusto Proiete Feb 08 '21 at 22:38

0 Answers0