我一直在努力在ASP.NET MVC 3應用程序上設置NLog v2,並且迄今爲止它工作得非常好。 (我使用的是官方nuGet存儲庫中的包)但是,當我嘗試更改日誌佈局以包含任何aspnet- *佈局渲染器時,出現配置錯誤。我已經減少了問題以下最低的用例:NLog在所有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:
我真的不知道發生了什麼事。我不確定那個渲染器會導致配置失效。我一整天的大部分時間都在喋喋不休,因此我希望有人能幫上忙。
謝謝!
謝謝。因爲錯過了這些,我現在感覺很傻。我非常感謝幫助! – Jacob 2011-06-16 19:21:11
它只是拒絕爲我工作。無論我嘗試什麼變量,輸出都是空白的:( – Storm 2015-05-14 09:15:25
正如有些答案所說:現在在NLog.Web中,我完全錯過了這一點,因爲所有在線信息都告訴你添加NLog.Extended – 4imble 2015-10-20 16:38:59