1

我目前正在开发自定义 ILogger 实现,并希望能够将自定义日志记录参数作为 Dictionary<string, string> 传递。所以我这样调用 Ilogger 的日志函数:

var customParameters = new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };
_logger.LogInformation("Testmessage, customParameters: {customParameters}", customParameters);

我的问题是如何在 ILoggerLog<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)方法中访问实际的字典?它似乎最终出现在 TState 参数中,但我无法弄清楚如何从那里实际提取 Dictionary 。

4

0 回答 0