NLog environment variable config files

asp.net-core, c#, nlog

Solution

Use `IHostingEnvironment.EnvironmentName` to get environment name and build file name at runtime:

env.ConfigureNLog($"nlog.{env.EnvironmentName}.config");

and don't forget about case sensitivity.

Problem

I'm stuck on this kinda simple problem. I'm trying to make multiple nlog config files, so that nlog can load them depending on environment variable. I've added `nlog.debug.config`, `nlog.production.config`, and changed `ASPNETCORE_ENVIRONMENT` to corresponding value, but no luck so far. I guess it's not that simple. I could set it up inside Startup.cs file, like this: ``` env.ConfigureNLog("nlog.environment.config"); ``` But is there some automatic way?

Original source