Author: gbayon
Date: Tue Jun 28 10:05:47 2005
New Revision: 202248
URL: http://svn.apache.org/viewcvs?rev=202248&view=rev
Log:
- Added new logging API
Added:
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ConfigurationSectionHandler.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ILog.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ILoggerFactoryAdapter.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/Log4NetLogger.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/Log4NetLoggerFA.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/NoOpLogger.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/NoOpLoggerFA.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/SimpleLogger.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/SimpleLoggerFA.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/LogManager.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/LogSetting.cs
Modified:
ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj
Modified: ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj?rev=202248&r1=202247&r2=202248&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj Tue Jun 28
10:05:47 2005
@@ -164,7 +164,62 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Logging\ConfigurationSectionHandler.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Logging\IDbConnectionProxy.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Logging\ILog.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Logging\ILoggerFactoryAdapter.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Logging\LogManager.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Logging\LogSetting.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Logging\Impl\Log4NetLogger.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Logging\Impl\Log4NetLoggerFA.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Logging\Impl\NoOpLogger.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Logging\Impl\NoOpLoggerFA.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Logging\Impl\SimpleLogger.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Logging\Impl\SimpleLoggerFA.cs"
SubType = "Code"
BuildAction = "Compile"
/>
Added:
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ConfigurationSectionHandler.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ConfigurationSectionHandler.cs?rev=202248&view=auto
==============================================================================
---
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ConfigurationSectionHandler.cs
(added)
+++
ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ConfigurationSectionHandler.cs
Tue Jun 28 10:05:47 2005
@@ -0,0 +1,163 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+
********************************************************************************/
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Configuration;
+using System.Xml;
+using ConfigurationException =
IBatisNet.Common.Exceptions.ConfigurationException;
+
+namespace IBatisNet.Common.Logging
+{
+ /// <summary>
+ /// Summary description for ConfigurationSectionHandler.
+ /// </summary>
+ public class ConfigurationSectionHandler: IConfigurationSectionHandler
+ {
+
+ #region Fields
+
+ private static readonly string LOGFACTORYADAPTER_ELEMENT =
"logFactoryAdapter";
+ private static readonly string
LOGFACTORYADAPTER_ELEMENT_TYPE_ATTRIB = "type";
+ private static readonly string ARGUMENT_ELEMENT = "arg";
+ private static readonly string ARGUMENT_ELEMENT_KEY_ATTRIB =
"key";
+ private static readonly string ARGUMENT_ELEMENT_VALUE_ATTRIB =
"value";
+
+ #endregion
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ public ConfigurationSectionHandler()
+ {
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="section"></param>
+ /// <returns></returns>
+ private LogSetting ReadConfiguration( XmlNode section )
+ {
+ XmlNode logFactoryElement = section.SelectSingleNode(
LOGFACTORYADAPTER_ELEMENT );
+
+ string factoryTypeString = string.Empty;
+ if (
logFactoryElement.Attributes[LOGFACTORYADAPTER_ELEMENT_TYPE_ATTRIB] != null )
+ factoryTypeString =
logFactoryElement.Attributes[LOGFACTORYADAPTER_ELEMENT_TYPE_ATTRIB].Value;
+
+ if ( factoryTypeString == string.Empty )
+ throw new ConfigurationException
+ ( "Required Attribute '"
+ + LOGFACTORYADAPTER_ELEMENT_TYPE_ATTRIB
+ + "' not found in element '"
+ + LOGFACTORYADAPTER_ELEMENT
+ + "'"
+ );
+
+
+ Type factoryType = null;
+ try
+ {
+ factoryType = Type.GetType( factoryTypeString,
true, false );
+ }
+ catch ( Exception e )
+ {
+ throw new ConfigurationException
+ ( "Unable to create type '" +
factoryTypeString + "'"
+ , e
+ );
+ }
+
+ XmlNodeList propertyNodes =
logFactoryElement.SelectNodes( ARGUMENT_ELEMENT );
+
+ NameValueCollection properties = new
NameValueCollection( null, new CaseInsensitiveComparer() );
+
+ foreach ( XmlNode propertyNode in propertyNodes )
+ {
+ string key = string.Empty;
+ string itsValue = string.Empty;
+
+ XmlAttribute keyAttrib =
propertyNode.Attributes[ARGUMENT_ELEMENT_KEY_ATTRIB];
+ XmlAttribute valueAttrib =
propertyNode.Attributes[ARGUMENT_ELEMENT_VALUE_ATTRIB];
+
+ if ( keyAttrib == null )
+ {
+ throw new ConfigurationException
+ ( "Required Attribute '"
+ + ARGUMENT_ELEMENT_KEY_ATTRIB
+ + "' not found in element '"
+ + ARGUMENT_ELEMENT
+ + "'"
+ );
+ }
+ else
+ {
+ key = keyAttrib.Value;
+ }
+
+ if ( valueAttrib != null )
+ {
+ itsValue = valueAttrib.Value;
+ }
+
+ properties.Add( key, itsValue );
+ }
+
+ return new LogSetting( factoryType, properties );
+ }
+
+ #region IConfigurationSectionHandler Members
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="parent"></param>
+ /// <param name="configContext"></param>
+ /// <param name="section"></param>
+ /// <returns></returns>
+ public object Create(object parent, object configContext,
System.Xml.XmlNode section)
+ {
+ int logFactoryElementsCount = section.SelectNodes(
LOGFACTORYADAPTER_ELEMENT ).Count;
+
+ if ( logFactoryElementsCount > 1 )
+ {
+ throw new ConfigurationException( "Only one
<logFactoryAdapter> element allowed" );
+ }
+ else if ( logFactoryElementsCount == 1 )
+ {
+ return ReadConfiguration( section );
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ #endregion
+ }
+}
+
Added: ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ILog.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ILog.cs?rev=202248&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ILog.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ILog.cs Tue Jun 28 10:05:47
2005
@@ -0,0 +1,195 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+
********************************************************************************/
+#endregion
+
+using System;
+
+namespace IBatisNet.Common.Logging
+{
+ /// <summary>
+ /// The 8 logging levels used by Log are (in order):
+ /// </summary>
+ public enum LogLevel
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ All = 0,
+ /// <summary>
+ ///
+ /// </summary>
+ Trace = 1,
+ /// <summary>
+ ///
+ /// </summary>
+ Debug = 2,
+ /// <summary>
+ ///
+ /// </summary>
+ Info = 3,
+ /// <summary>
+ ///
+ /// </summary>
+ Warn = 4,
+ /// <summary>
+ ///
+ /// </summary>
+ Error = 5,
+ /// <summary>
+ ///
+ /// </summary>
+ Fatal = 6,
+ /// <summary>
+ ///
+ /// </summary>
+ Off = 7,
+ }
+
+ /// <summary>
+ /// A simple logging interface abstracting logging APIs.
+ /// </summary>
+ public interface ILog
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ void Debug( object message );
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ void Debug( object message, Exception e );
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ void Error( object message );
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ void Error( object message, Exception e );
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ void Fatal( object message );
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ void Fatal( object message, Exception e );
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ void Info( object message );
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ void Info( object message, Exception e );
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ void Trace( object message );
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ void Trace( object message, Exception e );
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ void Warn( object message );
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ void Warn( object message, Exception e );
+
+ /// <summary>
+ ///
+ /// </summary>
+ bool IsDebugEnabled
+ {
+ get;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ bool IsErrorEnabled
+ {
+ get;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ bool IsFatalEnabled
+ {
+ get;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ bool IsInfoEnabled
+ {
+ get;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ bool IsTraceEnabled
+ {
+ get;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ bool IsWarnEnabled
+ {
+ get;
+ }
+ }
+}
Added: ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ILoggerFactoryAdapter.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ILoggerFactoryAdapter.cs?rev=202248&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ILoggerFactoryAdapter.cs
(added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/ILoggerFactoryAdapter.cs
Tue Jun 28 10:05:47 2005
@@ -0,0 +1,53 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+
********************************************************************************/
+#endregion
+
+using System;
+
+namespace IBatisNet.Common.Logging
+{
+ /// <summary>
+ /// LoggerFactoryAdapter interface is used internally by LogManager
+ /// Only developers wishing to write new SLF4J adapters need to
+ /// worry about this interface.
+ /// </summary>
+ public interface ILoggerFactoryAdapter
+ {
+ /// <summary>
+ /// Get a ILog instance by type
+ /// </summary>
+ /// <param name="type"></param>
+ /// <returns></returns>
+ ILog GetLogger( Type type );
+
+ /// <summary>
+ /// Get a ILog instance by type name
+ /// </summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ ILog GetLogger( string name );
+
+ }
+}
Added: ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/Log4NetLogger.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/Log4NetLogger.cs?rev=202248&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/Log4NetLogger.cs
(added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/Log4NetLogger.cs Tue
Jun 28 10:05:47 2005
@@ -0,0 +1,220 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+
********************************************************************************/
+#endregion
+
+using System;
+
+namespace IBatisNet.Common.Logging.Impl
+{
+ /// <summary>
+ /// Summary description for Log4NetLogger.
+ /// </summary>
+ public class Log4NetLogger : ILog
+ {
+
+ #region Fields
+
+ private log4net.ILog _log = null;
+
+ #endregion
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="log"></param>
+ internal Log4NetLogger( log4net.ILog log )
+ {
+ _log = log;
+ }
+
+ #region ILog Members
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsInfoEnabled
+ {
+ get { return _log.IsInfoEnabled; }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsWarnEnabled
+ {
+ get { return _log.IsWarnEnabled; }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsErrorEnabled
+ {
+ get { return _log.IsErrorEnabled; }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsFatalEnabled
+ {
+ get { return _log.IsFatalEnabled; }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsDebugEnabled
+ {
+ get { return _log.IsDebugEnabled; }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsTraceEnabled
+ {
+ get { return _log.IsDebugEnabled; }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Info(object message, Exception e)
+ {
+ _log.Info( message, e );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Info(object message)
+ {
+ _log.Info( message );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Debug(object message, Exception e)
+ {
+ _log.Debug( message, e );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Debug(object message)
+ {
+ _log.Debug( message );
+ }
+
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Warn(object message, Exception e)
+ {
+ _log.Warn( message, e );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Warn(object message)
+ {
+ _log.Warn( message );
+ }
+
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Trace(object message, Exception e)
+ {
+ _log.Debug( message, e );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Trace(object message)
+ {
+ _log.Debug( message );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Fatal(object message, Exception e)
+ {
+ _log.Fatal( message, e );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Fatal(object message)
+ {
+ _log.Fatal( message );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Error(object message, Exception e)
+ {
+ _log.Error( message, e );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Error(object message)
+ {
+ _log.Error( message );
+ }
+
+ #endregion
+ }
+}
Added: ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/Log4NetLoggerFA.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/Log4NetLoggerFA.cs?rev=202248&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/Log4NetLoggerFA.cs
(added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/Log4NetLoggerFA.cs Tue
Jun 28 10:05:47 2005
@@ -0,0 +1,106 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+
********************************************************************************/
+#endregion
+
+using System;
+using System.Collections.Specialized;
+using System.Configuration;
+using System.IO;
+using log4net.Config;
+
+namespace IBatisNet.Common.Logging.Impl
+{
+ /// <summary>
+ /// Concrete subclass of ILoggerFactoryAdapter specific to log4n.
+ /// </summary>
+ public class Log4NetLoggerFA : ILoggerFactoryAdapter
+ {
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="properties"></param>
+ public Log4NetLoggerFA(NameValueCollection properties)
+ {
+ string configurationType = string.Empty;
+
+ if ( properties["configType"] != null )
+ {
+ configurationType =
properties["configType"].ToUpper();
+ }
+
+ string configurationFile = string.Empty;
+ if ( properties["configFile"] != null )
+ {
+ configurationFile = properties["configFile"];
+ }
+
+ if ( configurationType == "FILE" )
+ {
+ if ( configurationFile == string.Empty )
+ throw new ConfigurationException(
"Configration property 'configurationFile' must be set for log4Net
configuration of type 'FILE'." );
+
+ if ( !File.Exists( configurationFile ) )
+ throw new ConfigurationException(
"log4net configuration file '" + configurationFile + "' does not exists" );
+ }
+
+ switch ( configurationType )
+ {
+ case "INLINE":
+ DOMConfigurator.Configure();
+ break;
+ case "FILE":
+ DOMConfigurator.Configure( new
FileInfo( configurationFile ) );
+ break;
+ default:
+ BasicConfigurator.Configure();
+ break;
+ }
+ }
+
+ #region ILoggerFactoryAdapter Members
+
+ /// <summary>
+ /// Get a ILog instance by type name
+ /// </summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public ILog GetLogger(string name)
+ {
+ return new Log4NetLogger( log4net.LogManager.GetLogger(
name ) );
+ }
+
+ /// <summary>
+ /// Get a ILog instance by type
+ /// </summary>
+ /// <param name="type"></param>
+ /// <returns></returns>
+ public ILog GetLogger(Type type)
+ {
+ return new Log4NetLogger( log4net.LogManager.GetLogger(
type ) );
+ }
+
+ #endregion
+ }
+}
Added: ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/NoOpLogger.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/NoOpLogger.cs?rev=202248&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/NoOpLogger.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/NoOpLogger.cs Tue Jun
28 10:05:47 2005
@@ -0,0 +1,205 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+
********************************************************************************/
+#endregion
+
+using System;
+
+namespace IBatisNet.Common.Logging.Impl
+{
+ /// <summary>
+ /// Summary description for NoOpLogger.
+ /// </summary>
+ public class NoOpLogger: ILog
+ {
+ /// <summary>
+ /// A NOP implementation.
+ /// </summary>
+ public NoOpLogger()
+ { }
+
+ #region Members of ILog
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Debug(object message)
+ {
+ // NOP
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Debug(object message, Exception e)
+ {
+ // NOP
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Error(object message)
+ {
+ // NOP
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Error(object message, Exception e)
+ {
+ // NOP
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Fatal(object message)
+ {
+ // NOP
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Fatal(object message, Exception e)
+ {
+ // NOP
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Info(object message)
+ {
+ // NOP
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Info(object message, Exception e)
+ {
+ // NOP
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Trace(object message)
+ {
+ // NOP
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Trace(object message, Exception e)
+ {
+ // NOP
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Warn(object message)
+ {
+ // NOP
+ }
+
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Warn(object message, Exception e)
+ {
+ // NOP
+ }
+
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsDebugEnabled
+ {
+ get { return false; }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsErrorEnabled
+ {
+ get { return false; }
+
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsFatalEnabled
+ {
+ get { return false; }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsInfoEnabled
+ {
+ get { return false; }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsTraceEnabled
+ {
+ get { return false; }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsWarnEnabled
+ {
+ get { return false; }
+ }
+
+ #endregion
+ }
+}
+
Added: ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/NoOpLoggerFA.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/NoOpLoggerFA.cs?rev=202248&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/NoOpLoggerFA.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/NoOpLoggerFA.cs Tue
Jun 28 10:05:47 2005
@@ -0,0 +1,58 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+
********************************************************************************/
+#endregion
+
+using System;
+
+namespace IBatisNet.Common.Logging.Impl
+{
+ /// <summary>
+ /// Summary description for NoOpLoggerFA.
+ /// </summary>
+ public class NoOpLoggerFA : ILoggerFactoryAdapter
+ {
+ private ILog _nopLogger = null;
+
+ public NoOpLoggerFA()
+ {
+ _nopLogger = new NoOpLogger();
+ }
+
+ #region ILoggerFactoryAdapter Members
+
+ public ILog GetLogger(Type type)
+ {
+ return _nopLogger;
+ }
+
+ ILog Logging.ILoggerFactoryAdapter.GetLogger(string name)
+ {
+ return _nopLogger;
+
+ }
+
+ #endregion
+ }
+}
Added: ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/SimpleLogger.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/SimpleLogger.cs?rev=202248&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/SimpleLogger.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/SimpleLogger.cs Tue
Jun 28 10:05:47 2005
@@ -0,0 +1,301 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+
********************************************************************************/
+#endregion
+
+using System;
+using System.Text;
+
+namespace IBatisNet.Common.Logging.Impl
+{
+ /// <summary>
+ /// Logger sending everything to the standard output error stream.
+ /// </summary>
+ public class SimpleLogger : ILog
+ {
+ private bool _showDateTime = false;
+ private bool _showLogName = false;
+ private string _logName = string.Empty;
+ private LogLevel _currentLogLevel = LogLevel.All;
+ private string _dateTimeFormat = string.Empty;
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="logName"></param>
+ /// <param name="logLevel"></param>
+ /// <param name="showDateTime">Include the current time in the
log message </param>
+ /// <param name="showLogName">Include the instance name in the
log message</param>
+ /// <param name="dateTimeFormat">The date and time format to
use in the log message </param>
+ public SimpleLogger( string logName, LogLevel logLevel
+ , bool showDateTime, bool showLogName, string
dateTimeFormat)
+ {
+ _logName = logName;
+ _currentLogLevel = logLevel;
+ _showDateTime = showDateTime;
+ _showLogName = showLogName;
+ _dateTimeFormat = dateTimeFormat;
+ }
+
+ /// <summary>
+ /// Do the actual logging.
+ /// This method assembles the message and write
+ /// the content of the message accumulated in the specified
+ /// StringBuffer to the appropriate output destination. The
+ /// default implementation writes to System.Console.Error.<p/>
+ /// </summary>
+ /// <param name="level"></param>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ private void Write( LogLevel level, object message, Exception e
)
+ {
+ // Use a StringBuilder for better performance
+ StringBuilder sb = new StringBuilder();
+ // Append date-time if so configured
+ if ( _showDateTime )
+ {
+ sb.Append( DateTime.Now );
+ sb.Append( " " );
+ }
+ // Append a readable representation of the log level
+ sb.Append( string.Format( "[{0}]",
level.ToString().ToUpper() ).PadRight( 8 ) );
+
+ // Append the name of the log instance if so configured
+ if ( _showLogName )
+ {
+ sb.Append( _logName ).Append( " - " );
+ }
+
+ // Append the message
+ sb.Append( message.ToString() );
+
+ // Append stack trace if not null
+ if ( e != null )
+ {
+ sb.AppendFormat( "\n{0}", e.ToString() );
+ }
+
+ // Print to the appropriate destination
+ System.Console.Error.WriteLine( sb.ToString() );
+ }
+
+ /// <summary>
+ /// Is the given log level currently enabled ?
+ /// </summary>
+ /// <param name="level"></param>
+ /// <returns></returns>
+ private bool IsLevelEnabled( LogLevel level )
+ {
+ int iLevel = (int)level;
+ int iCurrentLogLevel = (int)_currentLogLevel;
+
+ return ( iLevel >= iCurrentLogLevel );
+ }
+
+ #region ILog Members
+
+ /// <summary>
+ /// Log a debug message.
+ /// </summary>
+ /// <param name="message"></param>
+ public void Debug(object message)
+ {
+ Debug( message, null );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Debug(object message, Exception e)
+ {
+ if ( IsLevelEnabled( LogLevel.Debug ) )
+ {
+ Write( LogLevel.Debug, message, e );
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Error(object message)
+ {
+ Error( message, null );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Error(object message, Exception e)
+ {
+ if ( IsLevelEnabled( LogLevel.Error ) )
+ {
+ Write( LogLevel.Error, message, e );
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Fatal(object message)
+ {
+ Fatal( message, null );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Fatal(object message, Exception e)
+ {
+ if ( IsLevelEnabled( LogLevel.Fatal ) )
+ {
+ Write( LogLevel.Fatal, message, e );
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Info(object message)
+ {
+ Info( message, null );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Info(object message, Exception e)
+ {
+ if ( IsLevelEnabled( LogLevel.Info ) )
+ {
+ Write( LogLevel.Info, message, e );
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Trace(object message)
+ {
+ Trace( message, null );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Trace(object message, Exception e)
+ {
+ if ( IsLevelEnabled( LogLevel.Trace ) )
+ {
+ Write( LogLevel.Trace, message, e );
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public void Warn(object message)
+ {
+ Warn( message, null );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ /// <param name="e"></param>
+ public void Warn(object message, Exception e)
+ {
+ if ( IsLevelEnabled( LogLevel.Warn ) )
+ {
+ Write( LogLevel.Warn, message, e );
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsDebugEnabled
+ {
+ get { return IsLevelEnabled( LogLevel.Debug ); }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsErrorEnabled
+ {
+ get { return IsLevelEnabled( LogLevel.Error ); }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsFatalEnabled
+ {
+ get { return IsLevelEnabled( LogLevel.Fatal ); }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsInfoEnabled
+ {
+ get { return IsLevelEnabled( LogLevel.Info ); }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsTraceEnabled
+ {
+ get { return IsLevelEnabled( LogLevel.Trace ); }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public bool IsWarnEnabled
+ {
+ get { return IsLevelEnabled( LogLevel.Warn ); }
+ }
+
+ #endregion
+ }
+}
+
Added: ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/SimpleLoggerFA.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/SimpleLoggerFA.cs?rev=202248&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/SimpleLoggerFA.cs
(added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/Impl/SimpleLoggerFA.cs Tue
Jun 28 10:05:47 2005
@@ -0,0 +1,119 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+
********************************************************************************/
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+
+namespace IBatisNet.Common.Logging.Impl
+{
+ /// <summary>
+ /// Summary description for SimpleLoggerFactory.
+ /// </summary>
+ public class SimpleLoggerFA : ILoggerFactoryAdapter
+ {
+ private Hashtable _logs = Hashtable.Synchronized( new
Hashtable() );
+ private LogLevel _Level = LogLevel.All;
+ private bool _showDateTime = true;
+ private bool _showLogName = true;
+ private string _dateTimeFormat = string.Empty;
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="properties"></param>
+ public SimpleLoggerFA(NameValueCollection properties)
+ {
+ try
+ {
+ _Level = (LogLevel)Enum.Parse(
typeof(LogLevel), properties["level"], true );
+ }
+ catch ( Exception )
+ {
+ _Level = LogLevel.All;
+ }
+ try
+ {
+ _showDateTime = bool.Parse(
properties["showDateTime"] );
+ }
+ catch ( Exception )
+ {
+ _showDateTime = true;
+ }
+ try
+ {
+ _showLogName = bool.Parse(
properties["showLogName"] );
+ }
+ catch ( Exception )
+ {
+ _showLogName = true;
+ }
+ _dateTimeFormat = properties["dateTimeFormat"];
+ }
+
+ #region ILoggerFactoryAdapter Members
+
+ /// <summary>
+ /// Get a ILog instance by type
+ /// </summary>
+ /// <param name="type"></param>
+ /// <returns></returns>
+ public ILog GetLogger(Type type)
+ {
+ return GetLogger( type.FullName );
+ }
+
+ /// <summary>
+ /// Get a ILog instance by type name
+ /// </summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public ILog GetLogger(string name)
+ {
+ ILog log = _logs[name] as ILog;
+ if ( log == null )
+ {
+ log = new SimpleLogger( name, _Level,
_showDateTime, _showLogName, _dateTimeFormat );
+ _logs.Add( name, log );
+ }
+ return log;
+ }
+
+// public ILog GetLogger(Type type)
+// {
+// // TODO: Add SimpleLoggerFactory.GetLogger
implementation
+// return null;
+// }
+//
+// ILog Logging.ILoggerFactoryAdapter.GetLogger(string name)
+// {
+// // TODO: Add
SimpleLoggerFactory.Logging.ILoggerFactoryAdapter.GetLogger implementation
+// return null;
+// }
+
+ #endregion
+ }
+}
Added: ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/LogManager.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/LogManager.cs?rev=202248&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/LogManager.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/LogManager.cs Tue Jun 28
10:05:47 2005
@@ -0,0 +1,182 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+
********************************************************************************/
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Configuration;
+using IBatisNet.Common.Logging.Impl;
+
+namespace IBatisNet.Common.Logging
+{
+ /// <summary>
+ /// The LogManager can produce ILogFactory for various logging APIs,
+ /// most notably for log4net.
+ /// Other implemenations such as
+ /// * SimpleLogger
+ /// * NoOpLogger are also supported.
+ /// </summary>
+ public sealed class LogManager
+ {
+ private static ILoggerFactoryAdapter _adapter = null;
+ private static object _loadLock = new object();
+ private static readonly string IBATIS_SECTION_LOGIING =
"iBATIS/logging";
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="LogManager" />
class.
+ /// </summary>
+ /// <remarks>
+ /// Uses a private access modifier to prevent instantiation of
this class.
+ /// </remarks>
+ private LogManager()
+ { }
+
+ /// <summary>
+ ///
+ /// </summary>
+ private static ILoggerFactoryAdapter Adapter
+ {
+ get
+ {
+ if ( _adapter == null )
+ {
+ lock (_loadLock)
+ {
+ if (_adapter == null)
+ {
+ _adapter =
BuildLoggerFactoryAdapter();
+ }
+ }
+ }
+ return _adapter;
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="type"></param>
+ /// <returns></returns>
+ public static ILog GetLogger( Type type )
+ {
+ return Adapter.GetLogger( type );
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public static ILog GetLogger( string name )
+ {
+ return Adapter.GetLogger(name);
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ private static ILoggerFactoryAdapter BuildLoggerFactoryAdapter()
+ {
+ LogSetting setting = null;
+ try
+ {
+ setting =
(LogSetting)ConfigurationSettings.GetConfig( IBATIS_SECTION_LOGIING );
+ }
+ catch ( Exception ex )
+ {
+ ILoggerFactoryAdapter defaultFactory =
BuildDefaultLoggerFactoryAdapter();
+ ILog log = defaultFactory.GetLogger(
typeof(LogManager) );
+ log.Warn( "Unable to read configuration. Using
default logger.", ex );
+ return defaultFactory;
+ }
+
+ if ( setting!= null && !typeof ( ILoggerFactoryAdapter
).IsAssignableFrom( setting.FactoryAdapterType ) )
+ {
+ ILoggerFactoryAdapter defaultFactory =
BuildDefaultLoggerFactoryAdapter();
+ ILog log = defaultFactory.GetLogger(
typeof(LogManager) );
+ log.Warn( "Type " +
setting.FactoryAdapterType.FullName + " does not implement ILogFactory. Using
default logger" );
+ return defaultFactory;
+ }
+
+ ILoggerFactoryAdapter instance = null;
+
+ if (setting!=null)
+ {
+ if (setting.Properties.Count>0)
+ {
+ try
+ {
+ object[] args =
{setting.Properties};
+
+ instance =
(ILoggerFactoryAdapter)Activator.CreateInstance( setting.FactoryAdapterType,
args );
+ }
+ catch ( Exception ex )
+ {
+ ILoggerFactoryAdapter
defaultFactory = BuildDefaultLoggerFactoryAdapter();
+ ILog log =
defaultFactory.GetLogger( typeof(LogManager) );
+ log.Warn( "Unable to create
instance of type " + setting.FactoryAdapterType.FullName + ". Using default
logger.", ex );
+ return defaultFactory;
+ }
+ }
+ else
+ {
+ try
+ {
+ instance =
(ILoggerFactoryAdapter)Activator.CreateInstance( setting.FactoryAdapterType );
+ }
+ catch ( Exception ex )
+ {
+ ILoggerFactoryAdapter
defaultFactory = BuildDefaultLoggerFactoryAdapter();
+ ILog log =
defaultFactory.GetLogger( typeof(LogManager) );
+ log.Warn( "Unable to create
instance of type " + setting.FactoryAdapterType.FullName + ". Using default
logger.", ex );
+ return defaultFactory;
+ }
+ }
+ }
+ else
+ {
+ ILoggerFactoryAdapter defaultFactory =
BuildDefaultLoggerFactoryAdapter();
+ ILog log = defaultFactory.GetLogger(
typeof(LogManager) );
+ log.Warn( "Unable to read configuration
IBatisNet/logging. Using default logger (ConsoleLogger)." );
+ return defaultFactory;
+ }
+
+ return instance;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ private static ILoggerFactoryAdapter
BuildDefaultLoggerFactoryAdapter()
+ {
+ ILoggerFactoryAdapter simpleLogFactory = new
SimpleLoggerFA(new NameValueCollection( null, new CaseInsensitiveComparer() ));
+ return simpleLogFactory;
+ }
+ }
+}
+
Added: ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/LogSetting.cs
URL:
http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/LogSetting.cs?rev=202248&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/LogSetting.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Logging/LogSetting.cs Tue Jun 28
10:05:47 2005
@@ -0,0 +1,72 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: $
+ * $Date: $
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+
********************************************************************************/
+#endregion
+
+using System;
+using System.Collections.Specialized;
+
+namespace IBatisNet.Common.Logging
+{
+ /// <summary>
+ /// Setting for a logger.
+ /// </summary>
+ internal class LogSetting
+ {
+
+ #region Fields
+
+ private Type _factoryAdapterType= null;
+ private NameValueCollection _properties = null;
+
+ #endregion
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="factoryAdapterType"></param>
+ /// <param name="properties"></param>
+ public LogSetting ( Type factoryAdapterType ,
NameValueCollection properties )
+ {
+ _factoryAdapterType = factoryAdapterType;
+ _properties = properties;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public Type FactoryAdapterType
+ {
+ get { return _factoryAdapterType; }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ public NameValueCollection Properties
+ {
+ get { return _properties; }
+ }
+ }
+}