Bagzli Bagzli - 4 months ago 30
ASP.NET (C#) Question

Get ASP.NET application name with NLog

I am trying to figure out how to get the application name to be included in my file name when configuring NLog. Here is an example:

<target name="trace" xsi:type="File" FileName="C:\MyApp_${date:format=yyyyMMdd}-trace.log" layout="${longdate} ${exception:format=tostring}" />

However, I cant seem to be able to figure out what variable I need to use to pull the name of my application. I wish it to be something like:

<target name="trace" xsi:type="File" FileName="C:\${AppName}_${date:format=yyyyMMdd}-trace.log" layout="${longdate} ${exception:format=tostring}" />

I have gone through documentation here, but none of them seem to be able to get my application name, the best I have found is the
but that gives me the full path.

Is there a way to configure this?

The purpose of this is to have a single configuration file that is referenced by multiple applications, however they all would have their own log files.


edit: From the edited description I understand that you like to read the website name in IIS for a MVC 5 application.

You can use the ${iis-site-name} renderer for that.

You need to install NLog.Web NuGet package for that. No additional configuration is needed.