我正在尝试实现自定义 ILogger 。网核 3.1
CustomLogger 类实现了 ILogger。需要实施的方法之一是:
public class AuditLogLogger: ILogger
{
public IDisposable BeginScope<TState>(TState state)
{
return null;
}
public bool IsEnabled(LogLevel logLevel)
{
return true;
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
// How can I access the parameters I sent it from the controller?
}
}
从我的控制器中,我触发了 LogInformation 方法并传递了一个字符串和一个 KeyValuePair 列表,如下所示:
List<KeyValuePair<string, string>> udf = new List<KeyValuePair<string, string>>();
udf.Add(new KeyValuePair<string, string>("Test", "Test"));
_logger.LogInformation("This is a test", udf);
我的代码能够到达 Log<TState> 但我需要根据传入的参数执行一些逻辑。如何访问传递的参数?