前景说明:期望扩展一个作用域的日志参数 Chatgpt给出的代码配置是
configid=${sc:item=configid}
using (var conn = new OracleConnection(_connectionString))
{
LogUtil.Default.LogInfo($"dddddddd");
}
添加使用后发现configid值始终为空,问gpt,gpt始终说是因为我LogUtil.Default.LogInfo底层封装有问题 没有触发new LogEventInfo 导致property没有注入 但是LogUtil.Default.LogInfo的底层就是ILogger.Info(str) 无语了 反复问几遍 答得有理有据 就是全不对
解决:查看官网 原来不支持缩写"sc:" 应该使用全称 scopeproperty:
configid=${scopeproperty:item=configid}
https://github.com/NLog/NLog/wiki/ScopeProperty-Layout-Renderer
总结
问题可问 但记得求证 官网为证