在使用NLog在asp.net項目中發現,若是想單獨配其配置文件的位置時沒有像Log4Net的特性配置方案,可使其提供的 XmlLoggingConfiguration類來初始化:git
見:https://github.com/NLog/NLog/wiki/Configuration-filegithub
LogManager.Configuration = new XmlLoggingConfiguration("assets/someothername.config");
不過這種方法是不能在Web中使用的,你會看到奇怪的路徑。asp.net
用下面這個應該就好了。.net
LogManager.Configuration = new XmlLoggingConfiguration(AppDomain.CurrentDomain.BaseDirectory + @"config\NLog.config", true);