NLog在所有aspnet布局渲染器上引发配置异常

|| 我一直在努力在我的ASP.NET MVC 3应用程序上设置NLog v2,到目前为止,它一直运行良好。 (我使用的是官方nuGet存储库中的软件包)但是,当我尝试更改日志布局以包括任何aspnet- *布局渲染器时,出现配置错误。我已将问题减少到以下最小用例: 在configSections块中:
<section name=\"nlog\" type=\"NLog.Config.ConfigSectionHandler, NLog\"/>
Nlog块:
<nlog xmlns=\"http://www.nlog-project.org/schemas/NLog.xsd\"
      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" throwExceptions=\"true\">

<variable name=\"logDirectory\" value=\"C:\\Logs\" />
<targets>
  <target name=\"logFile\" xsi:type=\"File\" fileName=\"${logDirectory}\\app.log\"
      layout=\"${aspnet-user-identity}\" />
</targets>       

<rules>
  <logger name=\"*\" minlevel=\"Info\" writeTo=\"logfile\" />
</rules>
如果我使用不属于aspnet *系列的渲染器的任意组合来更改布局,则效果很好(我没有测试每个渲染器,但已经看了很多)。我得到的错误在这里:
Configuration Error 
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: An error occurred creating the configuration section handler for nlog: Exception occurred when loading configuration from C:\\..[snip]..\\web.config

Source Error: 


Line 16: </configSections>
Line 17: 
Line 18:   <nlog xmlns=\"http://www.nlog-project.org/schemas/NLog.xsd\"
Line 19:     xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" throwExceptions=\"true\">
Line 20: 
我真的不知道发生了什么。我不确定该渲染器会导致配置无效。我一天中大部分时间都在四处乱逛,却一无所获,所以我希望这里有人能提供帮助。 谢谢!     
已邀请:
        确保引用了
NLog.Extended
程序集,该程序集是在其中定义这些布局的,并且必须已由NuGet软件包以及引用添加到这些程序集:
<nlog xmlns=\"http://www.nlog-project.org/schemas/NLog.xsd\"
      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 
      throwExceptions=\"true\">

    <extensions>
        <add assembly=\"NLog.Extended\" />
    </extensions>

    <variable name=\"logDirectory\" value=\"C:\\Logs\" />

    <targets>
        <target name=\"logFile\" 
                xsi:type=\"File\" 
                fileName=\"${logDirectory}\\app.log\"
                layout=\"${aspnet-user-identity} ${message}\" />
    </targets>

    <rules>
        <logger name=\"*\" minlevel=\"Debug\" writeTo=\"logfile\" />
    </rules>

</nlog>
    
        从NLog 4.0开始,ASP.NET呈现器现在位于Nlog.Web中 http://nlog-project.org/2015/06/13/NLog-Extended_NLog-Web_and_NLog-Windows-Forms.html     
        如果达林不起作用的替代解决方案 您必须具有Darin提到的NLog.Extended http://nuget.org/packages/NLog.Extended 从NLog 2.0开始,您无需在配置XML中添加引用。 我的问题是我没有对NLog的硬引用。在我的Web层(我的web.config所在的位置)中扩展了NLog,因此编译器没有将文件复制到需要的位置。 通过向NLog添加硬引用可以轻松解决此问题。
//forces the compiler to include NLog.Extensions in all downstream output directories
private static AspNetApplicationValueLayoutRenderer blank = new AspNetApplicationValueLayoutRenderer();
    
        就我而言,我使用的是le_nlog扩展名,由于某种原因,它未安装在应用程序中! 所以我这样做是安装了* le_nlog *:
PM> Install-Package le_nlog
    

要回复问题请先登录注册