NLog - 如何记录所有请求信息
Nlog 具有一些 ASP.NET 日志记录功能(请参阅布局渲染器列表),
${aspnet-request}
例如记录表单项目,我需要知道项目名称。
${aspnet-request:form=myVariable}
但是如何记录未知项目中的所有内容呢? 例如
${aspnet-request:form}
The Nlog has some ASP.NET logging features (see the list of layout renderers), for example
${aspnet-request}
For log form item, I need to know name of item.
${aspnet-request:form=myVariable}
But how to log all from items, which hames in unknown?
For example
${aspnet-request:form}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己编写了自己的 LayoutRenderer(事实上,最近刚刚做了一些几乎相同的事情)——NLog 最好的部分之一是该框架的可扩展性。根据您的配置方式,配置将决定您如何引用/加载自定义布局渲染器,但就您可以做的事情而言,天空确实是限制。
在我的脑海中,您可以使用自定义渲染器采用两种方法之一:包装/扩展现有的 asp 请求渲染器并仅代理所有调用,或者以与 nlog 相同的方式获取请求对象的钩子(这很棘手;如果内存允许的话,它会调用获取 COM 实例)。
我采取的方法是将 NameValueCollection 嵌入到传出的 LogEventInfo 对象本身中(在属性字典中),然后使用自定义布局渲染器来提取该集合并渲染它。
I'd write my own LayoutRenderer, myself (in fact, just did something nearly identical, recently) - one of the best parts about NLog is how extensible the framework is. Depending on how you're doing configuration will determine how you reference/load your custom layoutrenderer, but the sky is really the limit in terms of what you can do.
Off the top of my head, you could take one of two approaches with a custom renderer: wrap/extend the existing asp request renderer and just proxy all calls, or get a hook to the request object the same way the nlog one does (which is tricky; it calls out to grab the COM instance, if memory serves).
The approach I took was to embed the NameValueCollection in the outgoing LogEventInfo object itself (in the properties dictionary), then use a custom layout renderer to extract that collection and render it.