asp.Net   发布时间:2022-04-07  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了asp.net-mvc – 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/scheR_796_11845@as/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLscheR_796_11845@a-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/scheR_796_11845@as/NLog.xsd"
Line 19:     xmlns:xsi="http://www.w3.org/2001/XMLscheR_796_11845@a-instance" throwExceptions="true">
Line 20:

我真的不知道发生了什么。我不知道该渲染器会导致配置无效。我一直在大声喧哗,没有任何地方,所以我希望有人能帮忙。

谢谢!

解决方法

请确保您引用了NLog.Extended程序集,这些程序集定义了哪些布局,哪些必须由NuGet软件包添加到引用中:
<nlog xmlns="http://www.nlog-project.org/scheR_796_11845@as/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLscheR_796_11845@a-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>

大佬总结

以上是大佬教程为你收集整理的asp.net-mvc – NLog在所有aspnet布局渲染器上抛出配置异常全部内容,希望文章能够帮你解决asp.net-mvc – NLog在所有aspnet布局渲染器上抛出配置异常所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。