Bagzli
Bagzli

Reputation: 6579

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, https://github.com/NLog/NLog/wiki/Layout-Renderers but none of them seem to be able to get my application name, the best I have found is the ${basedir} 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.

Upvotes: 4

Views: 4539

Answers (1)

Julian
Julian

Reputation: 36770

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.

Upvotes: 7

Related Questions