Add custom properties to Serilog

后端 未结 3 1153
名媛妹妹
名媛妹妹 2021-02-01 18:09

I\'m using Serilog with an MS SQL Server sink in my application. Let\'s assume I have defined the following class ...

public class Person
{
  public string First         


        
3条回答
  •  北海茫月
    2021-02-01 18:45

    If you're using the generic Microsoft ILogger interface you can use BeginScope;

    using (_logger.BeginScope(new Dictionary { { "LogEventType", logEventType }, { "UserName",  userName } }))
    {
        _logger.LogInformation(message, args);
    }
    

    This is discussed here; https://blog.rsuter.com/logging-with-ilogger-recommendations-and-best-practices/

提交回复
热议问题