.NET/Answer Detail

How to configure nlog in .netcore?

Smith
242 Points
91 Posts

I'm using .NetCore 2.0

In the nlog.config

<targets>
<!-- write logs to file -->
<target xsi:type="File" name="allfile" fileName=
"${basedir}\temp\nlog-all-${shortdate}.log"
layout="${longdate}| ${event-properties:item=
EventId.Id}|${logger}
|${uppercase:${level}}
|${message} ${exception}" />

But unable to create the log files. Anyone has any idea how to use ${basedir}.

Total Answered: 1
Total Marked As Answer: 0
Posted On: 10-Apr-2018 02:41
Share:   fb twitter linkedin
Answers
Brian
Participant
470 Points
65 Posts
 
 
Posted On: 15-Apr-2018 04:00

Update NLog 4.4 this is possible in one line (LayoutRenderer.Register)

And Add in program.cs LayoutRenderer.Register("basedir", (logEvent) => env.ContentRootPath);

public void Configure(IApplicationBuilder app, IHostingEnvironment env, 
ILoggerFactory loggerFactory)
{

//add NLog to ASP.NET Core
loggerFactory.AddNLog();

env.ConfigureNLog("nlog.config");

LayoutRenderer.Register("basedir", (logEvent) => env.ContentRootPath);

...
}

Blog

Active User (1)

 Log In to Chat