[转]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 ...
随机推荐
- 「BZOJ 3218」 a + b Problem
题目链接 戳我 \(Solution\) 题目为什么是\(a\ +\ b\ Problem\)啊?这和题面半毛钱关系都没有. 现在来讲一下这题的解法吧,我们首先看看没有奇怪的方格这一个条件吧. 其实没 ...
- 六、Note开发工具Visual Studio Code下载安装以及Visual Studio Code的使用
专业的人干专业的事,我们搞Node总不能真的使用文本编辑器傻乎乎的搞吧,文本编辑器来开发Node程序,效率太低,运行Node程序还需要在命令行单独敲命令.如果还需要调试程序,就更加麻烦了.所以我们需要 ...
- hbase安装 配置报错 zookeeper启动报错
zookeeper安装问题,使用独立安装的zookeeper export HBASE_MANAGES_ZK=false #如果使用独立安装的zookeeper这个地方就是false 创建zook ...
- 20165219 2017-2018-2 《Java程序设计》第5周学习总结
20165219 2017-2018-2 <Java程序设计>第5周学习总结 课本知识总结 第7章 内部类与异常类 一 1 内部类:类的一种成员 2 外嵌类:包含内部类的类称为内部类的外嵌 ...
- 拆半搜索binary_search
//binary_search用于在有序的区间用拆半查找搜索等于某值得元素 #include<algorithm> #include<iostream> using names ...
- f(!gotop.length) return false;
if (!$("p").length) return; if语句接收一个布尔值,如果布尔值为true则执行接下来的语句,布尔值为false则执行else关键词后的语句. JavaS ...
- 【bzoj4836】二元运算 分治FFT
Description 定义二元运算 opt 满足 现在给定一个长为 n 的数列 a 和一个长为 m 的数列 b ,接下来有 q 次询问.每次询问给定一个数字 c 你需要求出有多少对 (i, j) 使 ...
- luoguP3835 [模板]可持久化平衡树
https://www.luogu.org/problemnew/show/P3835 因为博主精力和实力有限,学不懂 fhq treap 了,因此只介绍 leafy tree 解法 leafy tr ...
- Error creating bean with name 'dateSource' defined in file 错误信息
问题的原因: 在web项目中搭建SSM框架,启动Tomcat时出现错误信息 有配置文件:applicationContext-mybatis.xml (Spring配置) spring-servlet ...
- POJ-3468-A Simple Problem with Integers(线段树 区间更新 区间和)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 139191 ...