我正在使用NLog在我的asp.net mvc(C#)應用程序中記錄異常。NLog不能在發佈模式下工作
NLog無法在發佈模式下工作。在調試模式下運行時也是如此。
可能是什麼問題?有沒有解決這個問題?
我正在使用NLog在我的asp.net mvc(C#)應用程序中記錄異常。NLog不能在發佈模式下工作
NLog無法在發佈模式下工作。在調試模式下運行時也是如此。
可能是什麼問題?有沒有解決這個問題?
設置環境變量:NLOG_INTERNAL_LOG_LEVEL和NLOG_INTERNAL_LOG_FILE,重新運行發佈版本然後檢查日誌文件,看看有什麼錯
我試過這個,但沒有骰子。它在調試模式下在本地工作,但是當我以釋放模式部署時,即使內部日誌記錄也不起作用。我很確定我的權限是足夠的。 – 2012-02-13 16:27:58
我有同樣的問題,因爲你:
我試着改變目錄,並改變權限無濟於事。我甚至嘗試啓用內部日誌記錄,但即使這樣也行不通!沒有失敗,沒有例外,沒有!
在做了一些更多的調查後,我找到了解決方案。 由於某種原因,NLog沒有加載配置文件AT ALL。我以編程方式啓用內部日誌記錄後意識到這一點。內部日誌報這個:
2012-02-13 11:34:40.3181 Debug Targets for MyMvcController by level:
2012-02-13 11:34:40.3181 Debug Trace =>
2012-02-13 11:34:40.3181 Debug Debug =>
2012-02-13 11:34:40.3181 Debug Info =>
2012-02-13 11:34:40.3181 Debug Warn =>
2012-02-13 11:34:40.3181 Debug Error =>
2012-02-13 11:34:40.3181 Debug Fatal =>
這基本上說,沒有任何日誌級別的定義的目標!絕對不正確!
我NLOG配置文件是因爲它可以簡單(且其設置複製到輸出目錄):
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true" throwExceptions="true">
<targets>
<target name="file" xsi:type="File" fileName="${basedir}/MyApplication.log" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="file" />
</rules>
</nlog>
我仍然不知道確切爲什麼這是發生,但移動將NLog配置放入web.config直接解決了問題。
轉移n日誌配置到應用程序的配置文件(web.config中,例如),然後再試一次。
確保您的目標文件「/日誌/」文件夾中保存。見下面
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
我試圖登錄到「根/ log.log」,並沒有工作,然後試圖「根/日誌/ log.log」和工作
低於滿配置文件。
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log" >
<!-- optional, add some variabeles
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<!--
Writing events to the a file with the date in the filename. -->
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>
<rules>
<!-- add your logging rules here -->
<!--
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"-->
<logger name="*" minlevel="Debug" writeTo="f" />
</rules>
</nlog>
我跟着所有其他的答案,但它沒有奏效。所以我嘗試了以下工作。
調用之前或調用LogManager.GetCurrentClassLogger();
後..我叫LogManager.Configuration
。
i。Ë
#region Constructor
public LoggerService()
{
var configuration = LogManager.Configuration;
_logger = LogManager.GetCurrentClassLogger();
//var configuration = LogManager.Configuration;
}
#endregion Constructor
FYI:我沒有做與任何配置。我只是叫它。
之所以它的工作,像其他人說:「我不」知道爲什麼「
對於任何人,誰不知道‘爲什麼n日誌不在督促環境中工作’:
祝你好運。
nlog配置文件是否包含在發佈版本中? – curtisk 2009-12-24 17:51:32
它存在於兩種模式中。 – Prasad 2009-12-24 17:54:15
因此,如果你在本地運行(即,只是按Ctrl-f5),它在發佈失敗?你有什麼錯誤嗎? – 2010-01-03 04:44:56