[转]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 ...
随机推荐
- 201621123012 《Java程序设计》第1周学习总结
1. 本章学习总结 学习了java的理论知识和它与C语言的差别,什么是JVM,区分JRE与JDK并学习JAVA环境的安装.熟悉控制台下的常用命令,java函数的编写.熟练使用编写JAVA所需要的工具( ...
- iOS应用打包完后再在开发者网站添加应用测试ID能够加入测试吗
1.明确指出 不行: 1.打包测试包前一定要先添加测试设备的UDID 2.添加测试的设备UDID一定要先于打包测试包,否则设备无法参加测试 3.使用蒲公英分享测试包,查看可参加测试的设备UDID 2. ...
- 基于 Token 的身份验证:JSON Web Token(JWT)
1.传统身份验证和JWT的身份验证 传统身份验证: HTTP 是一种没有状态的协议,也就是它并不知道是谁是访问应用.这里我们把用户看成是客户端,客户端使用用户名还有密码通过了身份验证,不过 ...
- CI框架部署后访问出现404
昨天新配置了一个PHP集成开发环境,安装完后,把项目放到Apache服务器的www目录下,发现只能打开首页,其他页面全部无法打开,当时比较纳闷,以为是服务器没有配置好,测试了一下,发现环境配置没有问题 ...
- linux系统安全及应用——账号安全(用户切换与提权)
一.su命令切换用户 su uesr 和 su - user 的区别:前者只切换登录人,shell环境还是上一个人的:后者表示注销当前用户,再进入新用户的shell. 查看切换记录:/var/log/ ...
- 【hadoop】 eclipse中的“run on hadoop”和打包成jar提交任务的区别
eclipse中的 调试运行 及 “run on hadoop”默认只是运行在单机上的,因为要想在集群中让程序分布式运行还要经历上传类文件.分发到各个节点等过程, 一个简单的“run on hadoo ...
- 华为敏捷DevOps实践:产品经理如何开好敏捷回顾会议
大家好,我是华为云DevCloud项目管理服务的产品经理 恒少:) 作为布道师和产品经理,出差各地接触客户是常态,经常和华为云的客户交流.布道.技术沙龙,但是线下交流,覆盖的用户总还是少数.我希望借助 ...
- (转)Delphi7中QuickReport组件(QReport报表)安装方法及重要属性
Delphi7中没有办法直接使用QuickReport组件,因为在Delphi7中没有将QuickReport组件包作为默认组件打包,如果要使用此组件,需要先安装一下. 打开delphi7,点 ...
- [AHOI2009]中国象棋 BZOJ1801 dp
题目描述 这次小可可想解决的难题和中国象棋有关,在一个N行M列的棋盘上,让你放若干个炮(可以是0个),使得没有一个炮可以攻击到另一个炮,请问有多少种放置方法.大家肯定很清楚,在中国象棋中炮的行走方式是 ...
- ssh 远程登录TX2
TX2 端SSH操作 安装: sudo apt-get install openssh-server 确认sshserver是否启动: ps -e |grep ssh 如果看到sshd那说明ssh-s ...