diff options
Diffstat (limited to 'slips/src/app/Marina/Infrastructure/Logging/Log4Net')
4 files changed, 80 insertions, 0 deletions
diff --git a/slips/src/app/Marina/Infrastructure/Logging/Log4Net/ILog4NetInitializationCommand.cs b/slips/src/app/Marina/Infrastructure/Logging/Log4Net/ILog4NetInitializationCommand.cs new file mode 100644 index 0000000..a688728 --- /dev/null +++ b/slips/src/app/Marina/Infrastructure/Logging/Log4Net/ILog4NetInitializationCommand.cs @@ -0,0 +1,8 @@ +using System.Xml;
+using log4net.Config;
+
+namespace Marina.Infrastructure.Logging.Log4Net {
+ public interface ILog4NetInitializationCommand {
+ void Execute( );
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Infrastructure/Logging/Log4Net/Log4NetInitializationCommand.cs b/slips/src/app/Marina/Infrastructure/Logging/Log4Net/Log4NetInitializationCommand.cs new file mode 100644 index 0000000..888a088 --- /dev/null +++ b/slips/src/app/Marina/Infrastructure/Logging/Log4Net/Log4NetInitializationCommand.cs @@ -0,0 +1,19 @@ +using System.Xml;
+using log4net.Config;
+using Marina.Infrastructure.Configuration;
+
+namespace Marina.Infrastructure.Logging.Log4Net {
+ public class Log4NetInitializationCommand : ILog4NetInitializationCommand {
+ private readonly XmlElement configuration;
+
+ public Log4NetInitializationCommand( ) : this( ConfigurationItems.Log4NetConfigFile.Value( ) ) {}
+
+ public Log4NetInitializationCommand( XmlElement configuration ) {
+ this.configuration = configuration;
+ }
+
+ public void Execute( ) {
+ XmlConfigurator.Configure( configuration );
+ }
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Infrastructure/Logging/Log4Net/Log4NetLog.cs b/slips/src/app/Marina/Infrastructure/Logging/Log4Net/Log4NetLog.cs new file mode 100644 index 0000000..a225f55 --- /dev/null +++ b/slips/src/app/Marina/Infrastructure/Logging/Log4Net/Log4NetLog.cs @@ -0,0 +1,23 @@ +using Marina.Infrastructure.Logging.Interfaces;
+
+namespace Marina.Infrastructure.Logging.Log4Net {
+ public class Log4NetLog : ILog {
+ private log4net.ILog logToAdapt;
+
+ public Log4NetLog( log4net.ILog logToAdapt ) {
+ this.logToAdapt = logToAdapt;
+ }
+
+ public void Informational( string message ) {
+ logToAdapt.Info( message );
+ }
+
+ public void Informational( string messageFormat, params object[] args ) {
+ logToAdapt.InfoFormat( messageFormat, args );
+ }
+
+ public void CriticalError( string messageFormat, params object[] args ) {
+ logToAdapt.ErrorFormat( messageFormat, args );
+ }
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Infrastructure/Logging/Log4Net/Log4NetLogFactory.cs b/slips/src/app/Marina/Infrastructure/Logging/Log4Net/Log4NetLogFactory.cs new file mode 100644 index 0000000..996557f --- /dev/null +++ b/slips/src/app/Marina/Infrastructure/Logging/Log4Net/Log4NetLogFactory.cs @@ -0,0 +1,30 @@ +using System;
+using log4net;
+using Marina.Infrastructure.Logging.Interfaces;
+using ILog=Marina.Infrastructure.Logging.Interfaces.ILog;
+
+namespace Marina.Infrastructure.Logging.Log4Net {
+ public class Log4NetLogFactory : ILogFactory {
+ private ILog4NetInitializationCommand initializationCommand;
+ private bool initialized;
+
+ public Log4NetLogFactory( ) : this( new Log4NetInitializationCommand( ) ) {}
+
+ public Log4NetLogFactory( ILog4NetInitializationCommand initializationCommand ) {
+ this.initializationCommand = initializationCommand;
+ }
+
+ public ILog CreateFor( Type typeThatRequiresLoggingServices ) {
+ WireUpConfiguration( );
+ return new Log4NetLog( LogManager.GetLogger( typeThatRequiresLoggingServices ) );
+ }
+
+ private void WireUpConfiguration( ) {
+ if ( initialized ) {
+ return;
+ }
+ initialized = true;
+ initializationCommand.Execute( );
+ }
+ }
+}
\ No newline at end of file |
