[转]Using NLog for ASP.NET Core to write custom information to the database
2017-03-07 14:18
597 查看
本文转自: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
I cannot make this work using ASP.NET Core and
I am using standard ASP.NET Core logging infrastructure and
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
For example,
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/
In the previous versions of NLog it was easily possible to map custom log properties to custom database columns using
LogEventInfoand
${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.Loggingpackage. At the runtime, my
Microsoft.Extensions.Logging.ILoggercontains additional
NLog.Extensions.Logging.NLogLoggerinstance, 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
stateparameter already supported by the
NLog.Extensions.Logging.NLogLogger.
For example,
NLogLoggercan check if
stateis 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/
相关文章推荐
- SQL Server Setup failed to obtain system account information for the ASPNET
- HTMLEditor Provider - How to write a custom provider for ASP.NET 2.0
- SQL Server Setup failed to obtain system account information for the ASPNET
- [收藏]The Baker's Dozen: 13 Tips for Building Database Web Applications Using ASP.NET 3.5, LINQ, and SQL Server 2005 Reporting Services
- [转]Setting the NLog database connection string in the ASP.NET Core appsettings.json
- Storing Binary Files Directly in the Database Using ASP.NET 2.0
- How to generate an RSS feed for your web site using ASP.NET
- ASP.NET datagrid直接导出为Excel Export to Excel from DataGrid (Using an Microsoft Access database)
- On the Way to Mastering ASP.NET: Introducing Custom Entity Classes
- How to get the Values of Selected Row from a Gridview using ASP.NET
- Using the Java APIs for Bluetooth, Part 2 - Putting the Core APIs to Work
- Downloading files from a server to client, using ASP.Net, when file size is too big for MemoryStream using Generic Handlers (ashx)
- Using jQuery with the ASP.NET CustomValidator Control(转)
- ASP.NET MVC- VIEW Using the TagBuilder Class to Build HTML Helpers Part 3
- asp.net中错误:"The state information is invalid for this page and might be corrupted."
- How to generate an RSS feed for your web site using ASP.NET
- How to handle the concurrency problems on ASP.Net Database
- Writing a Custom Membership Provider for the Login Control in ASP.NET 2.0
- Using the Index Server to create Query Page in asp.net
- PRB: "Requested Registry Access Is Not Allowed" Error Message When ASP.NET Application Tries to Write New EventSource in the Eve