DotNetCore/Answer Detail

Consider reloading NLog Configuration after having registered the IHttpContextAccessor

beginer
beginer
50 Points
20 Posts

I'm using nlog for logging but I'm getting following error:

Warn Missing IHttpContextAccessor. Has it been registered before loading NLog Configuration? Consider reloading NLog Configuration after having registered the IHttpContextAccessor.

 public Startup(IHostingEnvironment env)
{
   env.ConfigureNLog("nlog.config");
}
 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
          
            //add NLog to ASP.NET Core
            loggerFactory.AddNLog();

            //add NLog.Web
            app.AddNLogWeb();

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

Any one has any idea?

Total Answered: 1
Total Marked As Answer: 0
Posted On: 11-Jul-2018 02:28

Share:   fb twitter linkedin
Try to reload nlog.config after app.AddNLogWeb();
 - Jak  12-Jul-2018 05:02
Answers
kikme
kikme
8 Points
4 Posts
     

Use following code

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//add NLog to ASP.NET Core
loggerFactory.AddNLog();
//add NLog.Web
app.AddNLogWeb(); LayoutRenderer.Register("basedir", (logEvent) => env.ContentRootPath);
env.ConfigureNLog("nlog.config").Reload();  
}
Posted On: 21-Jul-2018 22:35
banner

Blog

Active User (13)

 Log In to Chat