NLog在所有aspnet布局渲染器上引发配置异常 [英] NLog throws configuration exception on all aspnet layout renderers

查看:156
本文介绍了NLog在所有aspnet布局渲染器上引发配置异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力在我的ASP.NET MVC 3应用程序上设置NLog v2,到目前为止,它运行良好. (我使用的是官方nuGet存储库中的软件包)但是,当我尝试更改日志布局以包括任何aspnet- *布局渲染器时,出现配置错误.我已将问题减少到以下最小用例:

I have been working to set up NLog v2 on my ASP.NET MVC 3 application and it has worked very well so far. (I'm using the package from the offical nuGet repository) However, when I try to change the log layout to include any of the aspnet-* layout renderers, I get a configuration error. I've reduced the problem to the following minimum use case:

在configSections块中:

In the configSections block:

<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 *系列的渲染器的任何组合来更改布局,则此方法效果很好(我没有测试每个渲染器,但已经查看了很多).我得到的错误在这里:

If I change layout use any combination of renderers that are not part of the aspnet* family, this works well (I haven't tested every one, but I've looked at quite a few). The error I get is here:

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: 

我真的不知道发生了什么.我不确定该渲染器会导致配置无效.我一天中大部分时间都在翻腾,却一无所获,所以我希望这里的人能为您提供帮助.

I have really no idea what's going on. I'm not sure what about that renderer causes the configuration to become invalid. I've been banging around at it most of the day and have gotten nowhere, so I'm hoping someone here can help.

谢谢!

推荐答案

确保已引用NLog.Extended程序集,该程序集是在其中定义这些布局的,并且必须已由NuGet包以及这些引用添加到这些程序集:

Make sure you have referenced the NLog.Extended assembly which is where those layouts are defined and which must have been added by the NuGet package as well to the references:

<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在所有aspnet布局渲染器上引发配置异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆