2016-07-26 8 views
3

NLogに問題があります。 私は、次のようにファイルNlog.configにNLogを設定している:ASP.NET MVC - NLogファイルのターゲットが見つかりません

<?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" 
     autoReload="true" 
     throwExceptions="true" 
     internalLogLevel="Trace" 
     internalLogFile="d:\temp\nlog-internal.log"> 

    <target xsi:type="File" name="log" fileName="${basedir}\logs\${date:format=dd}.log" 
     layout="${longdate} ${uppercase:${level}} ${message}" /> 


    <rules> 
    <logger name="*" minlevel="Debug" writeTo="log" /> 

    </rules> 
</nlog> 

そして、私はターゲットログがが見つからないというエラーが表示されます。私は本当に何ができるかわからない、誰かが似たような問題を抱えているかもしれない。

私は.NET 4.5を使用しています。

Nlog.configは、プロジェクトのメインディレクトリにあります。 ディレクトリ内のフルアクセス権を設定しました。

設定をweb.configファイルに移動しようとしましたが、エラーが引き続き表示されます。プロジェクトの

2016-07-26 09:17:25.6353 Warn Skipping unknown node: target 
2016-07-26 09:17:25.6353 Trace ParseRulesElement 
2016-07-26 09:17:25.6623 Error Error in Parsing Configuration File. Exception: NLog.NLogConfigurationException: Exception occurred when loading configuration from D:\Project\NLog.config ---> NLog.NLogConfigurationException: Target log not found. 
    w NLog.Config.XmlLoggingConfiguration.ParseLoggerElement(NLogXmlElement loggerElement, IList`1 rulesCollection) 
    w NLog.Config.XmlLoggingConfiguration.ParseRulesElement(NLogXmlElement rulesElement, IList`1 rulesCollection) 
    w NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLogXmlElement nlogElement, String filePath, Boolean autoReloadDefault) 
    w NLog.Config.XmlLoggingConfiguration.ParseTopLevel(NLogXmlElement content, String filePath, Boolean autoReloadDefault) 
    w NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors) 

構造:

Structure

更新(ミシェル・A.答えた後):私もNLog.configのプロパティを持っているファイル

Build Action = Content 
Copy to Output Directory = Copy always 

アップデート2 :解決策が見つかりました。問題は、私はバックスラッシュの代わりに、前方が

間違った構文スラッシュ持っているということでした。

fileName="${basedir}\logs\${date:format=dd}.log" 

正しい構文:

fileName="${basedir}/logs/${date:format=dd}.log" 
+0

解決策フォルダ内の/ logs /フォルダを確認し、現在のユーザーに読み取り権限または書き込み権限があるかどうかを確認します(存在する場合)。あなたの現在の写真では、それは解決の一部ではないので、これは問題になる可能性があります。 – Marco

+0

解決策が見つかりました。私は更新をしました。返信ありがとう:) –

答えて

1

アップデート2:私は解決策を見つけました。問題は、スラッシュの代わりにバックスラッシュを使用していたことです。

私はそれが問題ではないと確信しています。パスの登録時に評価されません。また、Windowsではスラッシュの種類は関係ありません。

問題は、XMLが<targets>を欠いていることをここにある:

<?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" 
     autoReload="true" 
     throwExceptions="true" 
     internalLogLevel="Trace" 
     internalLogFile="d:\temp\nlog-internal.log"> 

    <target xsi:type="File" name="log" fileName="${basedir}\logs\${date:format=dd}.log" 
     layout="${longdate} ${uppercase:${level}} ${message}" /> 


    <rules> 
    <logger name="*" minlevel="Debug" writeTo="log" /> 

    </rules> 
</nlog> 

次のようになります。

<?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" 
     autoReload="true" 
     throwExceptions="true" 
     internalLogLevel="Trace" 
     internalLogFile="d:\temp\nlog-internal.log"> 

    <targets> 
    <target xsi:type="File" name="log" fileName="${basedir}\logs\${date:format=dd}.log" 
      layout="${longdate} ${uppercase:${level}} ${message}" /> 
    </targets> 

    <rules> 
    <logger name="*" minlevel="Debug" writeTo="log" /> 

    </rules> 
</nlog> 

ヒント:NLog.Schema package

をインストールする場合は、自動補完とエラーチェックを取得します
+0

答えをありがとう。私のコードをチェックした後、あなたは正しい –

0

をあなたのbinフォルダにコピーされて、あなたのNLog設定ファイルですか?

(Visual Studioでプロパティファイルを確認してください)

+1

私のプロパティは次のとおりです。ビルドアクション=コンテンツ、コピー先出力先ディレクトリ=コピー常に –

+0

binフォルダに表示されている場合は問題ありません、ごめんなさいあなたに何が起こっているのか分かりません –

+0

解決策が見つかりました。返信いただきありがとうございます! :) –

関連する問題