博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[转]Using NLog for ASP.NET Core to write custom information to the database
阅读量:6295 次
发布时间:2019-06-22

本文共 1528 字,大约阅读时间需要 5 分钟。

本文转自:

In the previous versions of NLog it was easily possible to map custom log properties to custom database columns using LogEventInfo and ${event-properties} layout renderer:

LogEventInfo evt = new LogEventInfo(logLevel, "", message);evt.Properties["custom"] = "some data";log.Log(evt);

I cannot make this work using ASP.NET Core and NLog.Extensions.Logging.NLogLogger.

I am using standard and NLog.Extensions.Logging package. At the runtime, my Microsoft.Extensions.Logging.ILogger contains additional NLog.Extensions.Logging.NLogLogger instance, configured to write all the events to the database. I want to pass some dictionary-like object to Microsoft.Extensions.Logging.ILogger.Log() to make this information available to NLog layout renderers. Is it supported?

 

 

Hi May be you can use the state parameter of Log method to send the dictionary but you should have to write your own ILogger implementation to write it in NLog logger.

Actually we can't handle this scenario because the ILogger interface is part of .NET Core and we can't extend the method signature

 

Thanks I'll have deeper look into this, I thought that state parameter already supported by the NLog.Extensions.Logging.NLogLogger.

For example, NLogLogger can check if state is instance of Dictionary<string, string> (or Dictionary<object, object>) and push all data from there to the underlying LogEventInfo.Properties.

 

I think we should do something about this is the near future.  The aspnet logging is prepared for structural logging, but NLog not.

Related

 

转载地址:http://fopta.baihongyu.com/

你可能感兴趣的文章
10年重新出发
查看>>
2019年-年终总结
查看>>
聊聊elasticsearch的RoutingService
查看>>
让人抓头的Java并发(一) 轻松认识多线程
查看>>
从源码剖析useState的执行过程
查看>>
地包天如何矫正?
查看>>
中间件
查看>>
Android SharedPreferences
查看>>
css面试题
查看>>
Vue组建通信
查看>>
用CSS画一个带阴影的三角形
查看>>
前端Vue:函数式组件
查看>>
程鑫峰:1.26特朗.普力挺美元力挽狂澜,伦敦金行情分析
查看>>
safari下video标签无法播放视频的问题
查看>>
01 iOS中UISearchBar 如何更改背景颜色,如何去掉两条黑线
查看>>
对象的继承及对象相关内容探究
查看>>
Spring: IOC容器的实现
查看>>
Serverless五大优势,成本和规模不是最重要的,这点才是
查看>>
Nginx 极简入门教程!
查看>>
iOS BLE 开发小记[4] 如何实现 CoreBluetooth 后台运行模式
查看>>