10

NuGetパッケージを使用して、ASP.NetMVCプロジェクトでNLog2を使用するようにCommon.Loggingを構成しようとしています。以下のURLで提供される情報に基づいて、ロガーは適切に構成されていると思いますが、構成エラーが発生し続けます。

Common.Loggingの構成手順

NLog構成チュートリアル

指示に従って、web.configに以下を追加しました。

<configuration>
  <configSections>
      <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
      <sectionGroup name="common">
            <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
      </sectionGroup>
    </configSections>
    <common>
      <logging>
        <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
            <arg key="configType" value="INLINE" />
        </factoryAdapter>
      </logging>
    </common>
    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <targets>
        <target name="logfile" xsi:type="file" filename="e:\logfile.txt" layout="${date:format=yyyy/MM/dd HH:mm:ss} ${message}" />
      </targets>
      <rules>
        <logger name="*" minlevel="Trace" writeTo="logfile" />
      </rules>
    </nlog> 
    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
        </dependentAssembly>
      </assemblyBinding>
    </runtime>
</configuration>

私の知る限り、これが私がしなければならないすべてですが、Webプロジェクトを実行しようとすると構成エラーが発生します...

パーサーエラーメッセージ: common / loggingの構成セクションハンドラーの作成中にエラーが発生しました:タイプ'Common.Logging.NLog.NLogLoggerFactoryAdapter、Common.Logging.NLog20'を作成できません

何が欠けているか、何が間違っているかについて誰かが提案を提供できますか?

4

2 に答える 2

13

問題は、Common.Logging NuGetパッケージ(v2.0.0)によって追加されたデフォルトの構成が正しくないことであると思われます。

web.configのランタイムセクションを次のように変更する必要があります。

<dependentAssembly>
   <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="2.0.0.0" />
  </dependentAssembly>

oldVersion値に注意してください。これがエラーの原因のようです(少なくとも上記の質問で概説したシナリオに基づくと)。

この関連するGitHubの問題:Common.Logging /Common.Logging.NLog20NuGetパッケージで発生する可能性のある問題も参照してください。

于 2013-02-12T19:45:12.430 に答える
1

を使用して私のために働いた

<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog2">

それ以外の

<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">

最後に20対2に注意してください。

于 2014-04-05T13:44:07.393 に答える