NHibernate を OR/M として統合しようとしていますが、現在はエンタープライズ ライブラリのロギング アプリケーション ブロックを使用しています。NHibernate が log4net を使用してログを記録することは知っています。Enterprise Library を使用して NHibernate 関連のログを記録する方法の例はありますか?
4 に答える
nHibernate に log4net を使用させないのはなぜですか? はい、2 つを管理する必要がありますが、それ以外の場合は、log4net が EntLibrary にログを記録するためのアダプターを作成する必要があります。
私も EntLibrary を使用しており、nHibernate 用に存在する Log4Net を処理しています。彼らの dev ディスカッション グループで、彼らは log4net を depedancy として削除することについて話しましたが、それに関する作業は何も行われていないと思います。
これは私自身、ずっと疑問に思っていたことでした。NHibernate は Log4Net に強く依存していることを確認できます。したがって、Josh が指摘したように、アペンダーを作成する必要があります。
編集: NHibernate 3 の時点で、ハード依存関係はなくなりました。
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}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
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 & 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>