3

NHibernate を OR/M として統合しようとしていますが、現在はエンタープライズ ライブラリのロギング アプリケーション ブロックを使用しています。NHibernate が log4net を使用してログを記録することは知っています。Enterprise Library を使用して NHibernate 関連のログを記録する方法の例はありますか?

4

4 に答える 4

1

nHibernate に log4net を使用させないのはなぜですか? はい、2 つを管理する必要がありますが、それ以外の場合は、log4net が EntLibrary にログを記録するためのアダプターを作成する必要があります。

私も EntLibrary を使用しており、nHibernate 用に存在する Log4Net を処理しています。彼らの dev ディスカッション グループで、彼らは log4net を depedancy として削除することについて話しましたが、それに関する作業は何も行われていないと思います。

于 2009-03-20T18:51:26.997 に答える
1

これは私自身、ずっと疑問に思っていたことでした。NHibernate は Log4Net に強く依存していることを確認できます。したがって、Josh が指摘したように、アペンダーを作成する必要があります。

編集: NHibernate 3 の時点で、ハード依存関係はなくなりました。

于 2009-03-20T20:56:20.223 に答える
1

NHibernate 3 以降では、必要なバイナリを取得して構成するだけで、Microsoft の Enterprise Library 5.0 と一緒に Common Logging の実装を使用できます。Common.Logging.EntLib50を使用したNHibernate.Logging.CommonLoggingを参照してください。

これはオンラインのどこにも見つからなかったので、質問が古いにもかかわらず投稿すると思いました。以下は構成ファイルです (必要な参照を追加する必要があります)。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
 <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
 <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>
  </configSections>

  <loggingConfiguration name="" tracingEnabled="true"
    defaultCategory="General">
    <listeners>
      <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        source="Enterprise Library Logging" formatter="Text Formatter"
        log="trace.log" machineName="." traceOutputOptions="DateTime" />
      <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        fileName="MyLogNameGoesHere.txt" formatter="Text Formatter" traceOutputOptions="DateTime" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Event Log Listener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="Flat File Trace Listener" />
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Event Log Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>

  <appSettings>
    <add key="nhibernate-logger" value="NHibernate.Logging.CommonLogging.CommonLoggingLoggerFactory, NHibernate.Logging.CommonLogging" />
  </appSettings>
  <common>
    <logging>
      <factoryAdapter type="Common.Logging.EntLib.EntLibLoggerFactoryAdapter, Common.Logging.EntLib50"/>
    </logging>
  </common>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.2.1.4000" newVersion="3.2.1.4000" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
于 2012-03-20T22:31:13.087 に答える