[转]Using NLog for ASP.NET Core to write custom information to the database
本文转自:https://github.com/NLog/NLog/issues/1366
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 ASP.NET Core logging infrastructure 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 @dr-noise 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 @phenixdotnet 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://nlog.userecho.com/topics/21-make-structural-logging-possible/
[转]Using NLog for ASP.NET Core to write custom information to the database的更多相关文章
- Elasticsearch,Kibana,Logstash,NLog实现ASP.NET Core 分布式日志系统
Elasticsearch - 简介 Elasticsearch 作为核心的部分,是一个具有强大索引功能的文档存储库,并且可以通过 REST API 来搜索数据.它使用 Java 编写,基于 Apac ...
- 使用 NLog 给 Asp.Net Core 做请求监控
为了减少由于单个请求挂掉而拖垮整站的情况发生,给所有请求做统计是一个不错的解决方法,通过观察哪些请求的耗时比较长,我们就可以找到对应的接口.代码.数据表,做有针对性的优化可以提高效率.在 asp.ne ...
- NLog在asp.net core中的应用
Asp.net core中,自带的Log是在当selfhost运行时,在控制台中输出,不便于查阅,如果用一个log架框,把日志持久化,便于查询. NLog是一个免费的日志记录框架,专门为.net平台下 ...
- How to use Nlog for ASP.NET Core with csproj
1. Add dependency in csproj manually or using NuGet Install the latest: NLog.Web.AspNetCore 4.5+ Upd ...
- [转]ASP.NET Core 开发-Logging 使用NLog 写日志文件
本文转自:http://www.cnblogs.com/Leo_wl/p/5561812.html ASP.NET Core 开发-Logging 使用NLog 写日志文件. NLog 可以适用于 . ...
- ASP.NET Core 开发-Logging 使用NLog 写日志文件
ASP.NET Core 开发-Logging 使用NLog 写日志文件. NLog 可以适用于 .NET Core 和 ASP.NET Core . ASP.NET Core已经内置了日志支持,可以 ...
- ASP.NET Core 实战:使用 NLog 将日志信息记录到 MongoDB
一.前言 在项目开发中,日志系统是系统的一个重要组成模块,通过在程序中记录运行日志.错误日志,可以让我们对于系统的运行情况做到很好的掌控.同时,收集日志不仅仅可以用于诊断排查错误,由于日志同样也是大量 ...
- ASP.NET Core 添加NLog日志支持(VS2015update3&VS2017)
1.创建一个新的ASP.NET Core项目 2.添加项目依赖 NLog.Web.AspNetCore 3.在项目目录下添加nlog.config文件: <?xml version=" ...
- ASP.NET Core使用NLog记录日志
1.根目录新建nlog.config配置文件 <?xml version="1.0"?> <nlog xmlns="http://www.nlog-pr ...
随机推荐
- 在一个java类里,private int a; 什么时候要使用integer
private Integer index; if(index == null) index = 0; else this.index = index; Integer有一个明显的好处,就是它能比in ...
- POM很重要的3个关系
POM有3个很重要的关系:依赖.继承.合成. 1.依赖关系 <dependencies></dependencies> 2.继承 <parent></pare ...
- 190320运算符&数据类型
一.运算符 1.算术运算符 + 加 - 减 * 乘 / 除 ** 平方 // 整除 % 取余 2.比较运算符 == 等于 > 大于 < 小于 <= 小于等于 >= 大于等于 ! ...
- hdp 2.06 安装备忘
1,官方安装说明文档 http://docs.hortonworks.com/HDPDocuments/HDP2/HDP-2.0.6.0-Win/bk_installing_hdp_for_windo ...
- Axure 原型图
Axure RP 9最新版软件及汉化包下载 https://www.axure.com.cn/78629/ 点击下载 lang语言包放在根目录即可 Axure各种版本注册码 | 最新Axure R ...
- poll?transport=longpoll&connection...烦人的请求
2016-06-19 11:50 76人阅读 评论(0) 收藏 举报 分类: C#那点事 版权声明:本文为博主原创文章,未经博主允许不得转载. 1.问题描述: 最近使用miniui做了一个后台管理系 ...
- Tomcat 配置文件的解析
转载:https://www.cnblogs.com/sunshine-1/p/8990044.html https://www.cnblogs.com/kismetv/p/7228274.html ...
- EA添加时序图
在项目浏览器的空白处右击 http://blog.csdn.net/craftsman1970/article/details/70877530 不同于大部分面向对象或者UML的书籍,在讨论完类图/对 ...
- CentOS 7 系统区域和键盘设置
系统区域设置包括语言.键盘布局等,可以通过修改/etc/locale.conf配置文件或使用localectl实用程序来进行设置,一般在安装时设置为默认选择(英文.美式键盘)即可 修改配置文件 [ro ...
- AngularJs依赖注入写法笔记
下面两种依赖注入写法等价: [第一种] app.controller('lrNListingController', function (Notifier, Private, timefilter, ...