Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NLog - how to log all request information

Tags:

asp.net

nlog

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}
like image 979
MaxWave Avatar asked Nov 13 '22 19:11

MaxWave


1 Answers

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.

like image 99
JerKimball Avatar answered Dec 22 '22 08:12

JerKimball