我正在使用Microsoft.Extensions.Logging和NLog。我的应用程序是.NET Core 3.1。
我想使用自定义字段扩展日志记录。
是否可以,或者是否需要直接使用NLog?
<parameter name="@custom_guid" layout="${custom_guid}"/>
var config = new Dictionary<string, object>();
config.Add("custom_guid", "test");
_logger.LogInformation("Test message", config);
您可以这样做:
var config = new Dictionary<string, object>();
config.Add("custom_guid", "test");
using (_logger.BeginScope(config))
{
_logger.LogInformation("Test message");
}
并使用${mdlc:custom_guid}