Reputation: 22526
I'd like to use a logging system to trace a large web application. So far I've settled on NLog, for it's ease of configuration and API.
When tracing is enabled, I'm expecting to see lots of logging for various users. Is there a way to associate the individual log lines to a single request?
Upvotes: 1
Views: 420
Reputation: 22526
Found the answer after asking for it.
Each request is handled by a new thread in ASP.NET, hence the trick is marking the current thread with an unique name:
HttpRequest request = HttpContext.Current.Request;
Thread.CurrentThread.Name = Guid.NewGuid().ToString() + request.UserHostAddress;
This information can be read by NLog as ${threadname}
Upvotes: 1
Reputation: 27618
There are several LayoutRenderers that will output ASP information (I have not developed for ASP.NET so I can't say which (if any) would give you what you need). See this link for a list of LayoutRenderers:
http://nlog-project.org/wiki/Layout_renderers
From the NLog forum (at that same site) I can see that several people have had a problem getting the ASP.NET LayoutRenders to output anything (at least in NLog 2.0). The recommended solution so far (it should be fixed during Beta phase) is to add this to your NLog.config file:
<extensions>
<add assembly="NLog.Extended" />
</extensions>
Making sure that NLog.Extended.dll is in the same directory as NLog.dll
I can't post a link to the specific post in the forum because that forum does not provide links to individual posts, but it was in response to a question asked on October 28, 2010. The title of the question is: "Problem with NLOG and ASP.NET".
Upvotes: 0