jothi
jothi

Reputation: 362

NLog - Configure log file name from appsettings in web.config

What i want is to pull the Log File path from my Web.config appsettings section.

The scenario is that, the deployment team would replace all the files while deployment except the web.config. Hence even if i set up my NLog Config File, it would be replaced in the next deployment and all my settings would be lost.

Is there a way that I could read the appsettings from my config and use it to set my log file path?

<target xsi:type="File" name="FileLog" fileName="PULL_LOG_PATH_FROM_WEB_CONFIG/${shortdate}.log">

Upvotes: 2

Views: 3524

Answers (1)

Julian
Julian

Reputation: 36770

Use NLog.Extended and use ${appsetting:key1}.

So

<target xsi:type="File" name="FileLog" fileName="${appsetting:key1}/${shortdate}.log" />

See docs for ${appsetting}

update: this is currently only supported for ASP.NET and not for ASP.NET Core. See issue for ASP.NET Core: https://github.com/NLog/NLog/issues/2334

Upvotes: 6

Related Questions