« Return to Thread: Getting a web site name into log file name

Getting a web site name into log file name

by MikeGale :: Rate this Message:

Reply to Author | View in Thread

I'm using NLog to log in an ASP.NET 3.5 application programmed using Visual Studio 2008.  I'm pleased that it is easy to use and reliable.  Thanks for the good work.

(I needed to created a longdateutc layout renderer, to get dates in a time zone agnostic format.  This would be useful in the next version.)

I want some logs to contain the name of the web site they're from.

Along the lines of "www.whatever.com_xxx.log".

I configured NLog with something like 'fileName="${basedir}/_logs/${aspnet-application:variable=WebSitename}_xxx.log"' to achieve this.  Where the variable WebSiteName is assigned at application start.

To my surprise this fails in both the ApplicationEnd and the SessionEnd events.  (It works in app and session start events.)   (In other words the variable resolves to an empty string and I get a different filename.)

Has anyone got a simple way of achieving what I want?  (Without writing a layout renderer.)

 « Return to Thread: Getting a web site name into log file name

LightInTheBox - Buy quality products at wholesale price!