NLog を使用して、asp.net mvc (C#) アプリケーションで例外をログに記録しています。
NLog はリリース モードでは機能しません。デバッグモードで実行しているときも同じです。
何が問題なのですか?これに対する修正はありますか?
NLog を使用して、asp.net mvc (C#) アプリケーションで例外をログに記録しています。
NLog はリリース モードでは機能しません。デバッグモードで実行しているときも同じです。
何が問題なのですか?これに対する修正はありますか?
私はあなたと同じ問題を抱えていました:
ディレクトリを変更し、権限を無効に変更してみました。内部ロギングを有効にしてみましたが、それでもうまくいきませんでした。失敗も例外も何もありません!
さらに調査を行った後、私は解決策を見つけました。 何らかの理由で、NLogは構成ファイルをまったくロードしていませんでした。 プログラムで内部ロギングを有効にした後、これに気づきました。内部ロギングはこれを報告しました:
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構成ファイルは可能な限り単純でした(そしてそれは出力ディレクトリにコピーするように設定されていました):
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<!-- Other XML Sections -->
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="File" fileName="${basedir}/MyApplication.log" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="file" />
</rules>
</nlog>
</configuration>
なぜこれが起こったのかはまだ正確にはわかりませんが、NLog構成をweb.configに移動することで問題が直接解決されました。
参照:https ://github.com/nlog/NLog/wiki/Configuration-file#configuration-file-format
環境変数: NLOG_INTERNAL_LOG_LEVEL および NLOG_INTERNAL_LOG_FILE を設定し、リリース ビルドを再実行して、ログ ファイルをチェックし、何が問題なのかを確認します。
nlog 構成をアプリケーションの構成ファイル (web.config など) に転送し、再試行してください。
ターゲット ファイルが「/logs/」フォルダー内に保存されていることを確認します。下記参照
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
「root/log.log」にログインしようとしましたが機能しませんでした。次に「root/logs/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>