From 44b9a1e5578e00a94a8c7712bda5463841983005 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 2 Jan 2013 13:59:09 +0100 Subject: [PATCH 01/12] Added better support for exception formatting --- .../Common.Logging.2010-net40.csproj | 1 + src/Common.Logging/Common.Logging.2010.csproj | 1 + .../Logging/Simple/AbstractSimpleLogger.cs | 2 +- .../Logging/Simple/ExceptionFormatter.cs | 234 ++++++++++++++++++ 4 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 src/Common.Logging/Logging/Simple/ExceptionFormatter.cs diff --git a/src/Common.Logging/Common.Logging.2010-net40.csproj b/src/Common.Logging/Common.Logging.2010-net40.csproj index 6b04a6c..99cb7cf 100644 --- a/src/Common.Logging/Common.Logging.2010-net40.csproj +++ b/src/Common.Logging/Common.Logging.2010-net40.csproj @@ -94,6 +94,7 @@ Code + diff --git a/src/Common.Logging/Common.Logging.2010.csproj b/src/Common.Logging/Common.Logging.2010.csproj index 682d0b3..50affa4 100644 --- a/src/Common.Logging/Common.Logging.2010.csproj +++ b/src/Common.Logging/Common.Logging.2010.csproj @@ -92,6 +92,7 @@ Code + diff --git a/src/Common.Logging/Logging/Simple/AbstractSimpleLogger.cs b/src/Common.Logging/Logging/Simple/AbstractSimpleLogger.cs index fb541ed..d9195a8 100644 --- a/src/Common.Logging/Logging/Simple/AbstractSimpleLogger.cs +++ b/src/Common.Logging/Logging/Simple/AbstractSimpleLogger.cs @@ -177,7 +177,7 @@ protected virtual void FormatOutput(StringBuilder stringBuilder, LogLevel level, // Append stack trace if not null if (e != null) { - stringBuilder.Append(Environment.NewLine).Append(e.ToString()); + stringBuilder.Append(Environment.NewLine).Append(ExceptionFormatter.Format(e)); } } diff --git a/src/Common.Logging/Logging/Simple/ExceptionFormatter.cs b/src/Common.Logging/Logging/Simple/ExceptionFormatter.cs new file mode 100644 index 0000000..9218979 --- /dev/null +++ b/src/Common.Logging/Logging/Simple/ExceptionFormatter.cs @@ -0,0 +1,234 @@ +// Copyright © Anton Paar GmbH, 2004-2013 + +using System; +using System.Collections; +using System.Reflection; +using System.Text; +using System.Threading; +using System.Globalization; + +namespace Common.Logging.Simple +{ + /// + /// + internal static class ExceptionFormatter + { + // constants + private const String DELIMITER_LINE = + "================================================================================\r\n"; + private const String INNERMOST_DELIMITER_LINE = + "=======================================================(inner most exception)===\r\n"; + + internal static String Format(Exception exception) + { + return Format(exception, CultureInfo.InvariantCulture); + } + + internal static String Format(Exception exception, IFormatProvider formatProvider) + { + if (exception == null) + return null; + + // push all inner exceptions onto stack + var exceptionStack = new Stack(); + var currentException = exception; + while (currentException != null) + { + exceptionStack.Push(currentException); + currentException = currentException.InnerException; + } + + // go through inner exceptions in reverse order + var sb = new StringBuilder(); + for (Int32 i = 1; exceptionStack.Count > 0; i++) + { + currentException = (Exception)exceptionStack.Pop(); + _FormatSingleException(formatProvider, sb, currentException, i); + } + + // that's it; return result + return sb.ToString(); + } + + private static void _FormatSingleException(IFormatProvider formatProvider, StringBuilder sb, Exception exception, + Int32 exceptionIndex) + { + _OutputHeader(formatProvider, sb, exception, exceptionIndex); + _OutputDetails(formatProvider, sb, exception); + _OutputMessage(formatProvider, sb, exception); + _OutputProperties(formatProvider, sb, exception); + _OutputData(formatProvider, sb, exception); + _OutputStackTrace(formatProvider, sb, exception); + sb.Append(DELIMITER_LINE); + } + + private static void _OutputHeader(IFormatProvider formatProvider, StringBuilder sb, Exception exception, + Int32 exceptionIndex) + { + // output header: + // + // =======================================================(inner most exception)=== + // (index) exception-type-name + // ================================================================================ + // + sb.Append(exceptionIndex == 1 ? INNERMOST_DELIMITER_LINE : DELIMITER_LINE); + sb.AppendFormat(formatProvider, " ({0}) {1}\r\n", + exceptionIndex, exception.GetType().FullName); + sb.Append(DELIMITER_LINE); + } + + private static void _OutputDetails(IFormatProvider formatProvider, StringBuilder sb, Exception exception) + { + // output exception details: + // + // Method : set_Attributes + // Type : System.IO.FileSystemInfo + // Assembly : mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + // Assembly Path : C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll + // Source : mscorlib + // Thread : 123 'TestRunnerThread' + // Helplink : + // + String assemblyName, assemblyModuleName, typeName, methodName; + String source, helplink; + + _SafeGetTargetSiteInfo(exception, out assemblyName, out assemblyModuleName, out typeName, out methodName); + _SafeGetSourceAndHelplink(exception, out source, out helplink); + + sb.AppendFormat(formatProvider, + "Method : {0}\r\n" + + "Type : {1}\r\n" + + "Assembly : {2}\r\n" + + "Assembly Path : {3}\r\n" + + "Source : {4}\r\n" + + "Thread : {5} '{6}'\r\n" + + "Helplink : {7}\r\n", + methodName, typeName, assemblyName, assemblyModuleName, + source, + Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.Name, + helplink); + } + + private static void _OutputMessage(IFormatProvider formatProvider, StringBuilder sb, Exception exception) + { + // output exception message: + // + // Message: + // "..." + // + sb.AppendFormat(formatProvider, "\r\nMessage:\r\n\"{0}\"\r\n", + exception.Message); + } + + private static void _OutputProperties(IFormatProvider formatProvider, StringBuilder sb, Exception exception) + { + // output exception properties: + // + // Properties: + // ArgumentException.ParamName = "text" + // + var properties = exception.GetType().GetProperties(BindingFlags.FlattenHierarchy | + BindingFlags.Instance | BindingFlags.Public); + + Boolean first = true; + foreach (PropertyInfo property in properties) + { + if (property.DeclaringType == typeof(Exception)) + continue; + if (property.Name == "Message") + continue; + + if (first) + { + first = false; + sb.Append("\r\nProperties:\r\n"); + } + + Object propertyValue = ""; + if (property.CanRead) + propertyValue = property.GetValue(exception, null); + + var enumerableValue = propertyValue as IEnumerable; + + if (enumerableValue == null || propertyValue is String) + { + sb.AppendFormat(formatProvider, " {0}.{1} = \"{2}\"\r\n", + property.ReflectedType.Name, property.Name, propertyValue); + } + else + { + sb.AppendFormat(formatProvider, " {0}.{1} = {{\r\n", + property.ReflectedType.Name, property.Name); + + foreach (var item in enumerableValue) + sb.AppendFormat(" \"{0}\",\r\n", item != null ? item.ToString() : ""); + + sb.Append(" }\r\n"); + } + } + } + + private static void _OutputData(IFormatProvider formatProvider, StringBuilder sb, Exception exception) + { + // output exception properties: + // + // Data: + // Name = "value" + // + if (exception.Data.Count > 0) + { + sb.Append("\r\nData:\r\n"); + foreach (DictionaryEntry entry in exception.Data) + { + sb.AppendFormat(formatProvider, + "{0} = \"{1}\"\r\n", + entry.Key, entry.Value); + } + } + } + + private static void _OutputStackTrace(IFormatProvider formatProvider, StringBuilder sb, Exception exception) + { + // output stack trace: + // + // Stack Trace: + // at System.IO.FileSystemInfo.set_Attributes(FileAttributes value) + // at Common.Logging.LogStoreWriter._SetupRootFolder() + // at Common.Logging.LogStoreWriter..ctor(String rootPath, Int32 maxStoreSize, Int32 minBacklogs) + // + sb.AppendFormat(formatProvider, "\r\nStack Trace:\r\n{0}\r\n", + exception.StackTrace); + } + + private static void _SafeGetTargetSiteInfo(Exception exception, out String assemblyName, out String assemblyModulePath, + out String typeName, out String methodName) + { + assemblyName = ""; + assemblyModulePath = ""; + typeName = ""; + methodName = ""; + + MethodBase targetSite = exception.TargetSite; + + if (targetSite != null) + { + methodName = targetSite.Name; + Type type = targetSite.ReflectedType; + + typeName = type.FullName; + Assembly assembly = type.Assembly; + + assemblyName = assembly.FullName; + Module assemblyModule = assembly.ManifestModule; + + assemblyModulePath = assemblyModule.FullyQualifiedName; + } + } + + private static void _SafeGetSourceAndHelplink(Exception exception, out String source, out String helplink) + { + source = exception.Source; + helplink = exception.HelpLink; + } + } +} \ No newline at end of file From 82567a6ee7da1a6f3b12f1e320981a2a773d247c Mon Sep 17 00:00:00 2001 From: adamnation Date: Fri, 25 Jan 2013 20:07:18 -0800 Subject: [PATCH 02/12] initial project creation, removing System.Configuration dependency, adding MonoTouch - specific config reader --- .gitignore | 2 +- .../Common.Logging.MonoTouch.sln | 20 + .../Common.Logging.MonoTouch/AssemblyDoc.cs | 31 + .../Common.Logging.MonoTouch/AssemblyInfo.cs | 5 + .../Common.Logging.MonoTouch.csproj | 84 ++ .../Common.Logging.MonoTouch/LogManager.cs | 333 ++++++ .../Logging/Configuration/ArgUtils.cs | 316 +++++ .../Logging/Configuration/LogSetting.cs | 77 ++ .../MonoTouchConfigurationReader.cs | 48 + .../Logging/Configuration/NamespaceDoc.cs | 31 + .../Logging/ConfigurationException.cs | 84 ++ .../Logging/ConfigurationSectionHandler.cs | 232 ++++ .../Logging/CoverageExcludeAttribute.cs | 32 + .../AbstractCachingLoggerFactoryAdapter.cs | 132 +++ .../Logging/Factory/AbstractLogger.cs | 1033 +++++++++++++++++ .../Logging/Factory/NamespaceDoc.cs | 31 + .../Logging/FormatMessageHandler.cs | 32 + .../Logging/IConfigurationReader.cs | 49 + .../Common.Logging.MonoTouch/Logging/ILog.cs | 649 +++++++++++ .../Logging/ILoggerFactoryAdapter.cs | 49 + .../Logging/LogLevel.cs | 62 + .../Logging/LogManager.cs | 333 ++++++ .../Logging/MonoNet/CollectionsUtil.cs | 64 + .../Logging/NamespaceDoc.cs | 31 + .../Logging/Simple/AbstractSimpleLogger.cs | 263 +++++ .../AbstractSimpleLoggerFactoryAdapter.cs | 168 +++ .../Logging/Simple/ConsoleOutLogger.cs | 64 + .../Simple/ConsoleOutLoggerFactoryAdapter.cs | 81 ++ .../Logging/Simple/NamespaceDoc.cs | 31 + .../Logging/Simple/NoOpLogger.cs | 731 ++++++++++++ .../Simple/NoOpLoggerFactoryAdapter.cs | 102 ++ .../DefaultConfigurationReader.cs | 2 +- .../Logging/IConfigurationReader.cs | 2 - src/CommonAssemblyInfo.cs | 4 +- 34 files changed, 5202 insertions(+), 6 deletions(-) create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyDoc.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyInfo.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/LogManager.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/ArgUtils.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/LogSetting.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/NamespaceDoc.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationException.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationSectionHandler.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/CoverageExcludeAttribute.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractCachingLoggerFactoryAdapter.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractLogger.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/NamespaceDoc.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/FormatMessageHandler.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/IConfigurationReader.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILog.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILoggerFactoryAdapter.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogLevel.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogManager.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/MonoNet/CollectionsUtil.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/NamespaceDoc.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLogger.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLogger.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NamespaceDoc.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLogger.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLoggerFactoryAdapter.cs diff --git a/.gitignore b/.gitignore index 0707f88..6ca0331 100644 --- a/.gitignore +++ b/.gitignore @@ -47,4 +47,4 @@ src/Common.Logging.Log4Net129/Common.Logging.Log4Net129.xml src/Common.Logging.Log4Net1211/Common.Logging.Log4Net1211.xml src/Common.Logging.NLog10/Common.Logging.NLog10.xml src/Common.Logging.NLog20/Common.Logging.NLog20.xml -src/Common.Logging/Common.Logging.xml \ No newline at end of file +src/Common.Logging/Common.Logging.xml diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln new file mode 100644 index 0000000..b4b3f8d --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.MonoTouch", "Common.Logging.MonoTouch\Common.Logging.MonoTouch.csproj", "{DD9F81C2-BA9A-4212-9249-2300C62AFF6F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = Common.Logging.MonoTouch\Common.Logging.MonoTouch.csproj + EndGlobalSection +EndGlobal diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyDoc.cs new file mode 100644 index 0000000..12ad8f6 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyDoc.cs @@ -0,0 +1,31 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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 Common.Logging; + +/// +/// This assembly contains the core functionality of the Common.Logging framework. +/// In particular, checkout and for usage information. +/// +[CoverageExclude] +internal static class AssemblyDoc +{ + // serves as assembly summary for NDoc3 (http://ndoc3.sourceforge.net) +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyInfo.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyInfo.cs new file mode 100644 index 0000000..6a6d886 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyInfo.cs @@ -0,0 +1,5 @@ +using System.Reflection; +using System.Security; + +[assembly: AssemblyProduct("Common Logging Framework")] +[assembly: SecurityTransparent] \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj new file mode 100644 index 0000000..7f9b8a8 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj @@ -0,0 +1,84 @@ + + + + Debug + AnyCPU + 10.0.0 + 2.0 + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F} + {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Common.Logging.MonoTouch + Resources + Common.Logging.MonoTouch + + + True + full + False + bin\Debug + DEBUG; + prompt + 4 + False + + + none + True + bin\Release + prompt + 4 + False + + + + + + + + + + + + + + + + + + + + + + + + + + + ILoggerFactoryAdapter.cs + + + + + + CommonAssemblyInfo.cs + + + + + Code + + + + + + Code + + + + + + + + + \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/LogManager.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/LogManager.cs new file mode 100644 index 0000000..2f3b306 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/LogManager.cs @@ -0,0 +1,333 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Configuration; +using System.Diagnostics; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Security; +using System.Security.Permissions; +using Common.Logging.Simple; +using Common.Logging.Configuration; + +namespace Common.Logging +{ + /// + /// Use the LogManager's or + /// methods to obtain instances for logging. + /// + /// + /// For configuring the underlying log system using application configuration, see the example + /// at . + /// For configuring programmatically, see the example section below. + /// + /// + /// The example below shows the typical use of LogManager to obtain a reference to a logger + /// and log an exception: + /// + /// + /// ILog log = LogManager.GetLogger(this.GetType()); + /// ... + /// try + /// { + /// /* .... */ + /// } + /// catch(Exception ex) + /// { + /// log.ErrorFormat("Hi {0}", ex, "dude"); + /// } + /// + /// + /// The example below shows programmatic configuration of the underlying log system: + /// + /// + /// // create properties + /// NameValueCollection properties = new NameValueCollection(); + /// properties["showDateTime"] = "true"; + /// + /// // set Adapter + /// Common.Logging.LogManager.Adapter = new + /// Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(properties); + /// + /// + /// + /// + /// + /// + /// + /// Gilles Bayon + public static class LogManager + { + /// + /// The name of the default configuration section to read settings from. + /// + /// + /// You can always change the source of your configuration settings by setting another instance + /// on . + /// + public static readonly string COMMON_LOGGING_SECTION = "common/logging"; + + private static IConfigurationReader _configurationReader; + private static ILoggerFactoryAdapter _adapter; + private static readonly object _loadLock = new object(); + + /// + /// Performs static 1-time init of LogManager by calling + /// + static LogManager() + { + Reset(); + } + + /// + /// Reset the infrastructure to its default settings. This means, that configuration settings + /// will be re-read from section <common/logging> of your app.config. + /// + /// + /// This is mainly used for unit testing, you wouldn't normally use this in your applications.
+ /// Note: instances already handed out from this LogManager are not(!) affected. + /// Resetting LogManager only affects new instances being handed out. + ///
+ public static void Reset() + { + Reset(new DefaultConfigurationReader()); + } + + /// + /// Reset the infrastructure to its default settings. This means, that configuration settings + /// will be re-read from section <common/logging> of your app.config. + /// + /// + /// This is mainly used for unit testing, you wouldn't normally use this in your applications.
+ /// Note: instances already handed out from this LogManager are not(!) affected. + /// Resetting LogManager only affects new instances being handed out. + ///
+ /// + /// the instance to obtain settings for + /// re-initializing the LogManager. + /// + public static void Reset(IConfigurationReader reader) + { + lock (_loadLock) + { + if (reader == null) + { + throw new ArgumentNullException("reader"); + } + _configurationReader = reader; + _adapter = null; + } + } + + /// + /// Gets the configuration reader used to initialize the LogManager. + /// + /// Primarily used for testing purposes but maybe useful to obtain configuration + /// information from some place other than the .NET application configuration file. + /// The configuration reader. + public static IConfigurationReader ConfigurationReader + { + get + { + return _configurationReader; + } + } + + /// + /// Gets or sets the adapter. + /// + /// The adapter. + public static ILoggerFactoryAdapter Adapter + { + get + { + if (_adapter == null) + { + lock (_loadLock) + { + if (_adapter == null) + { + _adapter = BuildLoggerFactoryAdapter(); + } + } + } + return _adapter; + } + set + { + if (value == null) + { + throw new ArgumentNullException("Adapter"); + } + + lock (_loadLock) + { + _adapter = value; + } + } + } + + /// + /// Gets the logger by calling + /// on the currently configured using the type of the calling class. + /// + /// + /// This method needs to inspect the in order to determine the calling + /// class. This of course comes with a performance penalty, thus you shouldn't call it too + /// often in your application. + /// + /// + /// the logger instance obtained from the current + [MethodImpl(MethodImplOptions.NoInlining)] + public static ILog GetCurrentClassLogger() + { + StackFrame frame = new StackFrame(1, false); + ILoggerFactoryAdapter adapter = Adapter; + MethodBase method = frame.GetMethod(); + Type declaringType = method.DeclaringType; + return adapter.GetLogger(declaringType); + } + + /// + /// Gets the logger by calling + /// on the currently configured using the specified type. + /// + /// the logger instance obtained from the current + public static ILog GetLogger() + { + return Adapter.GetLogger(typeof(T)); + } + + /// + /// Gets the logger by calling + /// on the currently configured using the specified type. + /// + /// The type. + /// the logger instance obtained from the current + public static ILog GetLogger(Type type) + { + return Adapter.GetLogger(type); + } + + + /// + /// Gets the logger by calling + /// on the currently configured using the specified name. + /// + /// The name. + /// the logger instance obtained from the current + public static ILog GetLogger(string name) + { + return Adapter.GetLogger(name); + } + + + /// + /// Builds the logger factory adapter. + /// + /// a factory adapter instance. Is never null. + private static ILoggerFactoryAdapter BuildLoggerFactoryAdapter() + { + object sectionResult = null; + + ArgUtils.Guard(delegate + { + sectionResult = ConfigurationReader.GetSection(COMMON_LOGGING_SECTION); + } + , "Failed obtaining configuration for Common.Logging from configuration section 'common/logging'."); + + // configuration reader returned + if (sectionResult == null) + { + string message = (ConfigurationReader.GetType() == typeof(DefaultConfigurationReader)) + ? string.Format("no configuration section <{0}> found - suppressing logging output", COMMON_LOGGING_SECTION) + : string.Format("Custom ConfigurationReader '{0}' returned - suppressing logging output", ConfigurationReader.GetType().FullName); + Trace.WriteLine(message); + ILoggerFactoryAdapter defaultFactory = new NoOpLoggerFactoryAdapter(); + return defaultFactory; + } + + // ready to use ILoggerFactoryAdapter? + if (sectionResult is ILoggerFactoryAdapter) + { + Trace.WriteLine(string.Format("Using ILoggerFactoryAdapter returned from custom ConfigurationReader '{0}'", ConfigurationReader.GetType().FullName)); + return (ILoggerFactoryAdapter)sectionResult; + } + + // ensure what's left is a LogSetting instance + ArgUtils.Guard(delegate + { + ArgUtils.AssertIsAssignable("sectionResult", sectionResult.GetType()); + } + , "ConfigurationReader {0} returned unknown settings instance of type {1}" + , ConfigurationReader.GetType().FullName, sectionResult.GetType().FullName); + + ILoggerFactoryAdapter adapter = null; + ArgUtils.Guard(delegate + { + adapter = BuildLoggerFactoryAdapterFromLogSettings((LogSetting)sectionResult); + } + , "Failed creating LoggerFactoryAdapter from settings"); + + return adapter; + } + + /// + /// Builds a instance from the given + /// using . + /// + /// + /// the instance. Is never null + private static ILoggerFactoryAdapter BuildLoggerFactoryAdapterFromLogSettings(LogSetting setting) + { + ArgUtils.AssertNotNull("setting", setting); + // already ensured by LogSetting + // AssertArgIsAssignable("setting.FactoryAdapterType", setting.FactoryAdapterType + // , "Specified FactoryAdapter does not implement {0}. Check implementation of class {1}" + // , typeof(ILoggerFactoryAdapter).FullName + // , setting.FactoryAdapterType.AssemblyQualifiedName); + + ILoggerFactoryAdapter adapter = null; + + ArgUtils.Guard(delegate + { + if (setting.Properties != null + && setting.Properties.Count > 0) + { + object[] args = { setting.Properties }; + + adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType, args); + } + else + { + adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType); + } + } + , "Unable to create instance of type {0}. Possible explanation is lack of zero arg and single arg NameValueCollection constructors" + , setting.FactoryAdapterType.FullName + ); + + // make sure + ArgUtils.AssertNotNull("adapter", adapter, "Activator.CreateInstance() returned "); + return adapter; + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/ArgUtils.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/ArgUtils.cs new file mode 100644 index 0000000..52b615e --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/ArgUtils.cs @@ -0,0 +1,316 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Diagnostics; + +namespace Common.Logging.Configuration +{ + /// + /// Various utility methods for using during factory and logger instance configuration + /// + /// Erich Eichinger + public static class ArgUtils + { + /// + /// A delegate converting a string representation into the target type + /// + public delegate T ParseHandler(string strValue); + + private static readonly Hashtable s_parsers; + + /// + /// Initialize all members before any of this class' methods can be accessed (avoids beforeFieldInit) + /// + static ArgUtils() + { + s_parsers = new Hashtable(); + RegisterTypeParser(delegate(string s) { return Convert.ToBoolean(s); }); + RegisterTypeParser(delegate(string s) { return Convert.ToInt16(s); }); + RegisterTypeParser(delegate(string s) { return Convert.ToInt32(s); }); + RegisterTypeParser(delegate(string s) { return Convert.ToInt64(s); }); + RegisterTypeParser(delegate(string s) { return Convert.ToSingle(s); }); + RegisterTypeParser(delegate(string s) { return Convert.ToDouble(s); }); + RegisterTypeParser(delegate(string s) { return Convert.ToDecimal(s); }); + } + + /// + /// Adds the parser to the list of known type parsers. + /// + /// + /// .NET intrinsic types are pre-registerd: short, int, long, float, double, decimal, bool + /// + public static void RegisterTypeParser(ParseHandler parser) + { + s_parsers[typeof(T)] = parser; + } + + /// + /// Retrieves the named value from the specified . + /// + /// may be null + /// the value's key + /// if is not null, the value returned by values[name]. null otherwise. + public static string GetValue(NameValueCollection values, string name) + { + return GetValue(values, name, null); + } + + /// + /// Retrieves the named value from the specified . + /// + /// may be null + /// the value's key + /// the default value, if not found + /// if is not null, the value returned by values[name]. null otherwise. + public static string GetValue(NameValueCollection values, string name, string defaultValue) + { + if (values != null) + { + foreach (string key in values.AllKeys) + { + if (string.Compare(name, key, true) == 0) + { + return values[name]; + } + } + } + return defaultValue; + } + + /// + /// Returns the first nonnull, nonempty value among its arguments. + /// + /// + /// Returns null, if the initial list was null or empty. + /// + /// + public static string Coalesce(params string[] values) + { + return Coalesce(delegate(string v) { return !string.IsNullOrEmpty(v); }, values); + } + + /// + /// Returns the first nonnull, nonempty value among its arguments. + /// + /// + /// Also + /// + public static T Coalesce(Predicate predicate, params T[] values) where T : class + { + if (values == null || values.Length == 0) + { + return null; + } + + if (predicate == null) + { + predicate = delegate(T v) { return v != null; }; + } + + for (int i = 0; i < values.Length; i++) + { + T val = values[i]; + if (predicate(val)) + { + return val; + } + } + return null; + } + + /// + /// Tries parsing into an enum of the type of . + /// + /// the default value to return if parsing fails + /// the string value to parse + /// the successfully parsed value, otherwise. + public static T TryParseEnum(T defaultValue, string stringValue) where T : struct + { + if (!typeof(T).IsEnum) + { + throw new ArgumentException(string.Format("Type '{0}' is not an enum type", typeof(T).FullName)); + } + + T result = defaultValue; + if (string.IsNullOrEmpty(stringValue)) + { + return defaultValue; + } + try + { + result = (T)Enum.Parse(typeof(T), stringValue, true); + } + catch + { + Console.Error.WriteLine(string.Format("WARN: failed converting value '{0}' to enum type '{1}'", stringValue, defaultValue.GetType().FullName)); + } + return result; + } + + /// + /// Tries parsing into the specified return type. + /// + /// the default value to return if parsing fails + /// the string value to parse + /// the successfully parsed value, otherwise. + public static T TryParse(T defaultValue, string stringValue) + { + T result = defaultValue; + if (string.IsNullOrEmpty(stringValue)) + { + return defaultValue; + } + + ParseHandler parser = s_parsers[typeof(T)] as ParseHandler; + if (parser == null) + { + throw new ArgumentException(string.Format("There is no parser registered for type {0}", typeof(T).FullName)); + } + + try + { + result = parser(stringValue); + } + catch + { + Console.Error.WriteLine(string.Format("WARN: failed converting value '{0}' to type '{1}' - returning default '{2}'", stringValue, typeof(T).FullName, result)); + } + return result; + } + + /// + /// Throws a if is null. + /// + public static T AssertNotNull(string paramName, T val) where T : class + { + if (ReferenceEquals(val, null)) + { + throw new ArgumentNullException(paramName); + } + return val; + } + + /// + /// Throws a if is null. + /// + public static T AssertNotNull(string paramName, T val, string messageFormat, params object[] args) where T : class + { + if (ReferenceEquals(val, null)) + { + throw new ArgumentNullException(paramName, string.Format(messageFormat, args)); + } + return val; + } + + /// + /// Throws a if an object of type is not + /// assignable to type . + /// + public static Type AssertIsAssignable(string paramName, Type valType) + { + return AssertIsAssignable(paramName + , valType + , string.Format("Type '{0}' of parameter '{1}' is not assignable to target type '{2}'" + , valType == null ? "" : valType.AssemblyQualifiedName + , paramName + , typeof(T).AssemblyQualifiedName) + ); + } + + /// + /// Throws a if an object of type is not + /// assignable to type . + /// + public static Type AssertIsAssignable(string paramName, Type valType, string messageFormat, params object[] args) + { + if (valType == null) + { + throw new ArgumentNullException("valType"); + } + + if (!typeof(T).IsAssignableFrom(valType)) + { + throw new ArgumentOutOfRangeException(paramName, valType, string.Format(messageFormat, args)); + } + return valType; + } + + /// + /// An anonymous action delegate with no arguments and no return value. + /// + /// + public delegate void Action(); + + /// + /// Ensures any exception thrown by the given is wrapped with an + /// . + /// + /// + /// If already throws a ConfigurationException, it will not be wrapped. + /// + /// the action to execute + /// the message to be set on the thrown + /// args to be passed to to format the message + public static void Guard(Action action, string messageFormat, params object[] args) + { + Guard(delegate + { + action(); + return 0; + } + , messageFormat, args); + } + + /// + /// An anonymous action delegate with no arguments and no return value. + /// + /// + public delegate T Function(); + + /// + /// Ensures any exception thrown by the given is wrapped with an + /// . + /// + /// + /// If already throws a ConfigurationException, it will not be wrapped. + /// + /// the action to execute + /// the message to be set on the thrown + /// args to be passed to to format the message + public static T Guard(Function function, string messageFormat, params object[] args) + { + try + { + return function(); + } + catch (ConfigurationException) + { + throw; + } + catch (Exception ex) + { + throw new ConfigurationException(string.Format(messageFormat, args), ex); + } + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/LogSetting.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/LogSetting.cs new file mode 100644 index 0000000..d54a622 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/LogSetting.cs @@ -0,0 +1,77 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 Common.Logging.Configuration +{ + /// + /// Container used to hold configuration information from config file. + /// + /// Gilles Bayon + public class LogSetting + { + #region Fields + + private readonly Type _factoryAdapterType = null; + private readonly NameValueCollection _properties = null; + + #endregion + + /// + /// + /// + /// + /// The type + /// that will be used for creating + /// + /// + /// Additional user supplied properties that are passed to the + /// 's constructor. + /// + public LogSetting(Type factoryAdapterType, NameValueCollection properties) + { + ArgUtils.AssertNotNull("factoryAdapterType", factoryAdapterType); + ArgUtils.AssertIsAssignable("factoryAdapterType", factoryAdapterType + , "Type {0} does not implement {1}", factoryAdapterType.AssemblyQualifiedName, typeof(ILoggerFactoryAdapter).FullName); + + _factoryAdapterType = factoryAdapterType; + _properties = properties; + } + + /// + /// The type that will be used for creating + /// instances. + /// + public Type FactoryAdapterType + { + get { return _factoryAdapterType; } + } + + /// + /// Additional user supplied properties that are passed to the 's constructor. + /// + public NameValueCollection Properties + { + get { return _properties; } + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs new file mode 100644 index 0000000..3aed086 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs @@ -0,0 +1,48 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 MonoTouch.Foundation; + +namespace Common.Logging.Configuration +{ + /// + /// MonoTouch implementation of configuration reader. Each section corresponds to a plist on the device. + /// + /// adamnation + public class MonoTouchConfigurationReader : IConfigurationReader + { + /// + /// Parses the configuration section and returns the resulting object. + /// + /// Path to the plist on the device + /// + /// NSDictionary of the settings in the plist. + /// + /// + ///

+ /// Primary purpose of this method is to allow us to load settings from a plist on the device. + ///

+ ///
+ /// + public object GetSection(string sectionName) + { + return new NSDictionary (NSBundle.MainBundle.PathForResource (sectionName, null)); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/NamespaceDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/NamespaceDoc.cs new file mode 100644 index 0000000..fa66a7e --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/NamespaceDoc.cs @@ -0,0 +1,31 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 + +namespace Common.Logging.Configuration +{ + /// + /// This namespace contains various utility classes. + /// + [CoverageExclude] + internal static class NamespaceDoc + { + // serves as namespace summary for NDoc3 (http://ndoc3.sourceforge.net) + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationException.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationException.cs new file mode 100644 index 0000000..6254b54 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationException.cs @@ -0,0 +1,84 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Runtime.Serialization; + +namespace Common.Logging +{ + /// + /// The exception that is thrown when a configuration system error has occurred with Common.Logging + /// + /// Mark Pollack + [Serializable] + public class ConfigurationException : ApplicationException + { + #region Constructor (s) / Destructor + + /// Creates a new instance of the ObjectsException class. + public ConfigurationException() + { + } + + /// + /// Creates a new instance of the ConfigurationException class. with the specified message. + /// + /// + /// A message about the exception. + /// + public ConfigurationException(string message) : base(message) + { + } + + /// + /// Creates a new instance of the ConfigurationException class with the specified message + /// and root cause. + /// + /// + /// A message about the exception. + /// + /// + /// The root exception that is being wrapped. + /// + public ConfigurationException(string message, Exception rootCause) + : base(message, rootCause) + { + } + + /// + /// Creates a new instance of the ConfigurationException class. + /// + /// + /// The + /// that holds the serialized object data about the exception being thrown. + /// + /// + /// The + /// that contains contextual information about the source or destination. + /// + protected ConfigurationException( + SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationSectionHandler.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationSectionHandler.cs new file mode 100644 index 0000000..81262e5 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationSectionHandler.cs @@ -0,0 +1,232 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Runtime.CompilerServices; +using System.Xml; +using Common.Logging.Simple; +using Common.Logging.Configuration; + +namespace Common.Logging +{ + /// + /// Used in an application's configuration file (App.Config or Web.Config) to configure the logging subsystem. + /// + /// + /// An example configuration section that writes log messages to the Console using the + /// built-in Console Logger. + /// + /// <configuration> + /// <configSections> + /// <sectionGroup name="common"> + /// <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> + /// </sectionGroup> + /// </configSections> + /// <common> + /// <logging> + /// <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging"> + /// <arg key="showLogName" value="true" /> + /// <arg key="showDataTime" value="true" /> + /// <arg key="level" value="ALL" /> + /// <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" /> + /// </factoryAdapter> + /// </logging> + /// </common> + /// </configuration> + /// + /// + public class ConfigurationSectionHandler : IConfigurationSectionHandler + { + + #region Fields + + private static readonly string LOGFACTORYADAPTER_ELEMENT = "factoryAdapter"; + 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 + + /// + /// Ensure static fields get initialized before any class member + /// can be accessed (avoids beforeFieldInit) + /// + static ConfigurationSectionHandler() + { } + + /// + /// Constructor + /// + public ConfigurationSectionHandler() + { } + + /// + /// Retrieves the of the logger the use by looking at the logFactoryAdapter element + /// of the logging configuration element. + /// + /// + /// + /// A object containing the specified type that implements + /// along with zero or more properties that will be + /// passed to the logger factory adapter's constructor as an . + /// + 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 + { + if (String.Compare(factoryTypeString, "CONSOLE", true) == 0) + { + factoryType = typeof(ConsoleOutLoggerFactoryAdapter); + } + else if (String.Compare(factoryTypeString, "TRACE", true) == 0) + { + factoryType = typeof(TraceLoggerFactoryAdapter); + } + else if (String.Compare(factoryTypeString, "NOOP", true) == 0) + { + factoryType = typeof(NoOpLoggerFactoryAdapter); + } + else + { + 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 = null; + properties = new NameValueCollection(); // defaults to case-insensitive keys + + 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); + } + + /// + /// Verifies that the logFactoryAdapter element appears once in the configuration section. + /// + /// settings of a parent section - atm this must always be null + /// Additional information about the configuration process. + /// The configuration section to apply an XPath query too. + /// + /// A object containing the specified logFactoryAdapter type + /// along with user supplied configuration properties. + /// + public LogSetting Create(LogSetting parent, object configContext, XmlNode section) + { + if (parent != null) + { + throw new ConfigurationException("parent configuration sections are not allowed"); + } + + int logFactoryElementsCount = section.SelectNodes(LOGFACTORYADAPTER_ELEMENT).Count; + + if (logFactoryElementsCount > 1) + { + throw new ConfigurationException("Only one element allowed"); + } + else if (logFactoryElementsCount == 1) + { + return ReadConfiguration(section); + } + else + { + return null; + } + } + + #region IConfigurationSectionHandler Members + + /// + /// Verifies that the logFactoryAdapter element appears once in the configuration section. + /// + /// The parent of the current item. + /// Additional information about the configuration process. + /// The configuration section to apply an XPath query too. + /// + /// A object containing the specified logFactoryAdapter type + /// along with user supplied configuration properties. + /// + object IConfigurationSectionHandler.Create(object parent, object configContext, XmlNode section) + { + return Create(parent as LogSetting, configContext, section); + } + + #endregion + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/CoverageExcludeAttribute.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/CoverageExcludeAttribute.cs new file mode 100644 index 0000000..60e7650 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/CoverageExcludeAttribute.cs @@ -0,0 +1,32 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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; + +/// +/// Indicates classes or members to be ignored by NCover +/// +/// +/// Note, the name is chosen, because TestDriven.NET uses it as //ea argument to "Test With... Coverage" +/// +/// Erich Eichinger +[AttributeUsage(AttributeTargets.All)] +internal class CoverageExcludeAttribute : Attribute +{} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractCachingLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractCachingLoggerFactoryAdapter.cs new file mode 100644 index 0000000..6a5fc61 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractCachingLoggerFactoryAdapter.cs @@ -0,0 +1,132 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 Common.Logging.Factory +{ + /// + /// An implementation of that caches loggers handed out by this factory. + /// + /// + /// Implementors just need to override . + /// + /// Erich Eichinger + public abstract class AbstractCachingLoggerFactoryAdapter : ILoggerFactoryAdapter + { + private readonly Hashtable _cachedLoggers; + + /// + /// Creates a new instance, the logger cache being case-sensitive. + /// + protected AbstractCachingLoggerFactoryAdapter():this(true) + {} + + /// + /// Creates a new instance, the logger cache being . + /// + /// + protected AbstractCachingLoggerFactoryAdapter(bool caseSensitiveLoggerCache) + { + _cachedLoggers = (caseSensitiveLoggerCache) + ? new Hashtable() + : CollectionsUtil.CreateCaseInsensitiveHashtable(); + } + + /// + /// Purges all loggers from cache + /// + protected void ClearLoggerCache() + { + lock (_cachedLoggers) + { + _cachedLoggers.Clear(); + } + } + + /// + /// Create the specified named logger instance + /// + /// + /// Derived factories need to implement this method to create the + /// actual logger instance. + /// + protected abstract ILog CreateLogger(string name); + + #region ILoggerFactoryAdapter Members + + /// + /// Get a ILog instance by . + /// + /// Usually the of the current class. + /// + /// An ILog instance either obtained from the internal cache or created by a call to . + /// + public ILog GetLogger(Type type) + { + return GetLoggerInternal(type.FullName); + } + + /// + /// Get a ILog instance by name. + /// + /// Usually a 's Name or FullName property. + /// + /// An ILog instance either obtained from the internal cache or created by a call to . + /// + public ILog GetLogger(string name) + { + return GetLoggerInternal(name); + } + + /// + /// Get or create a ILog instance by name. + /// + /// Usually a 's Name or FullName property. + /// + /// An ILog instance either obtained from the internal cache or created by a call to . + /// + private ILog GetLoggerInternal(string name) + { + ILog log = _cachedLoggers[name] as ILog; + if (log == null) + { + lock (_cachedLoggers) + { + log = _cachedLoggers[name] as ILog; + if (log == null) + { + log = CreateLogger(name); + if (log == null) + { + throw new ArgumentException(string.Format("{0} returned null on creating logger instance for name {1}", this.GetType().FullName, name)); + } + _cachedLoggers.Add(name, log); + } + } + } + return log; + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractLogger.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractLogger.cs new file mode 100644 index 0000000..012a20b --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractLogger.cs @@ -0,0 +1,1033 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 FormatMessageCallback = System.Action; + +namespace Common.Logging.Factory +{ + /// + /// Provides base implementation suitable for almost all logger adapters + /// + /// Erich Eichinger + [Serializable] + public abstract class AbstractLogger : ILog + { + #region FormatMessageCallbackFormattedMessage + + /// + /// Format message on demand. + /// + protected class FormatMessageCallbackFormattedMessage + { + private volatile string cachedMessage; + + private readonly IFormatProvider formatProvider; + private readonly FormatMessageCallback formatMessageCallback; + + /// + /// Initializes a new instance of the class. + /// + /// The format message callback. + public FormatMessageCallbackFormattedMessage(FormatMessageCallback formatMessageCallback) + { + this.formatMessageCallback = formatMessageCallback; + } + + /// + /// Initializes a new instance of the class. + /// + /// The format provider. + /// The format message callback. + public FormatMessageCallbackFormattedMessage(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + this.formatProvider = formatProvider; + this.formatMessageCallback = formatMessageCallback; + } + + /// + /// Calls and returns result. + /// + /// + public override string ToString() + { + if (cachedMessage == null && formatMessageCallback != null) + { + formatMessageCallback(FormatMessage); + } + return cachedMessage; + } + + private string FormatMessage(string format, params object[] args) + { + cachedMessage = string.Format(formatProvider, format, args); + return cachedMessage; + } + } + + #endregion + + #region StringFormatFormattedMessage + + /// + /// Format string on demand. + /// + protected class StringFormatFormattedMessage + { + private volatile string cachedMessage; + + private readonly IFormatProvider FormatProvider; + private readonly string Message; + private readonly object[] Args; + + /// + /// Initializes a new instance of the class. + /// + /// The format provider. + /// The message. + /// The args. + public StringFormatFormattedMessage(IFormatProvider formatProvider, string message, params object[] args) + { + FormatProvider = formatProvider; + Message = message; + Args = args; + } + + /// + /// Runs on supplied arguemnts. + /// + /// string + public override string ToString() + { + if (cachedMessage == null && Message != null) + { + cachedMessage = string.Format(FormatProvider, Message, Args); + } + return cachedMessage; + } + } + + #endregion + + /// + /// Represents a method responsible for writing a message to the log system. + /// + protected delegate void WriteHandler(LogLevel level, object message, Exception exception); + + /// + /// Holds the method for writing a message to the log system. + /// + private readonly WriteHandler Write; + + /// + /// Creates a new logger instance using for + /// writing log events to the underlying log system. + /// + /// + protected AbstractLogger() + { + Write = GetWriteHandler(); + if (Write == null) + { + Write = new WriteHandler(WriteInternal); + } + } + + /// + /// Override this method to use a different method than + /// for writing log events to the underlying log system. + /// + /// + /// Usually you don't need to override thise method. The default implementation returns + /// null to indicate that the default handler should be + /// used. + /// + protected virtual WriteHandler GetWriteHandler() + { + return null; + } + + /// + /// Checks if this logger is enabled for the level. + /// + /// + /// Override this in your derived class to comply with the underlying logging system + /// + public abstract bool IsTraceEnabled { get; } + + /// + /// Checks if this logger is enabled for the level. + /// + /// + /// Override this in your derived class to comply with the underlying logging system + /// + public abstract bool IsDebugEnabled { get; } + + /// + /// Checks if this logger is enabled for the level. + /// + /// + /// Override this in your derived class to comply with the underlying logging system + /// + public abstract bool IsInfoEnabled { get; } + + /// + /// Checks if this logger is enabled for the level. + /// + /// + /// Override this in your derived class to comply with the underlying logging system + /// + public abstract bool IsWarnEnabled { get; } + + /// + /// Checks if this logger is enabled for the level. + /// + /// + /// Override this in your derived class to comply with the underlying logging system + /// + public abstract bool IsErrorEnabled { get; } + + /// + /// Checks if this logger is enabled for the level. + /// + /// + /// Override this in your derived class to comply with the underlying logging system + /// + public abstract bool IsFatalEnabled { get; } + + /// + /// Actually sends the message to the underlying log system. + /// + /// the level of this log event. + /// the message to log + /// the exception to log (may be null) + protected abstract void WriteInternal(LogLevel level, object message, Exception exception); + + #region Trace + + /// + /// Log a message object with the level. + /// + /// The message object to log. + public virtual void Trace(object message) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, message, null); + } + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + public virtual void Trace(object message, Exception exception) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, message, exception); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + public virtual void TraceFormat(IFormatProvider formatProvider, string format, params object[] args) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new StringFormatFormattedMessage(formatProvider, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + public virtual void TraceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new StringFormatFormattedMessage(formatProvider, format, args), exception); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + public virtual void TraceFormat(string format, params object[] args) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new StringFormatFormattedMessage(null, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + public virtual void TraceFormat(string format, Exception exception, params object[] args) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new StringFormatFormattedMessage(null, format, args), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Trace(FormatMessageCallback formatMessageCallback) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + public virtual void Trace(FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + public virtual void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); + } + + #endregion + + #region Debug + + /// + /// Log a message object with the level. + /// + /// The message object to log. + public virtual void Debug(object message) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, message, null); + } + + /// + /// Log a message object with the level including + /// the stack Debug of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack Debug. + public virtual void Debug(object message, Exception exception) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, message, exception); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + public virtual void DebugFormat(IFormatProvider formatProvider, string format, params object[] args) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new StringFormatFormattedMessage(formatProvider, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + public virtual void DebugFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new StringFormatFormattedMessage(formatProvider, format, args), exception); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + public virtual void DebugFormat(string format, params object[] args) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new StringFormatFormattedMessage(null, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + public virtual void DebugFormat(string format, Exception exception, params object[] args) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new StringFormatFormattedMessage(null, format, args), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Debug(FormatMessageCallback formatMessageCallback) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Debug. + public virtual void Debug(FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Debug. + public virtual void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); + } + + #endregion + + #region Info + + /// + /// Log a message object with the level. + /// + /// The message object to log. + public virtual void Info(object message) + { + if (IsInfoEnabled) + Write(LogLevel.Info, message, null); + } + + /// + /// Log a message object with the level including + /// the stack Info of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack Info. + public virtual void Info(object message, Exception exception) + { + if (IsInfoEnabled) + Write(LogLevel.Info, message, exception); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + public virtual void InfoFormat(IFormatProvider formatProvider, string format, params object[] args) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new StringFormatFormattedMessage(formatProvider, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + public virtual void InfoFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new StringFormatFormattedMessage(formatProvider, format, args), exception); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + public virtual void InfoFormat(string format, params object[] args) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new StringFormatFormattedMessage(null, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + public virtual void InfoFormat(string format, Exception exception, params object[] args) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new StringFormatFormattedMessage(null, format, args), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Info(FormatMessageCallback formatMessageCallback) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Info. + public virtual void Info(FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Info. + public virtual void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); + } + + #endregion + + #region Warn + + /// + /// Log a message object with the level. + /// + /// The message object to log. + public virtual void Warn(object message) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, message, null); + } + + /// + /// Log a message object with the level including + /// the stack Warn of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack Warn. + public virtual void Warn(object message, Exception exception) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, message, exception); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Warnrmation. + /// The format of the message object to log. + /// + public virtual void WarnFormat(IFormatProvider formatProvider, string format, params object[] args) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new StringFormatFormattedMessage(formatProvider, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Warnrmation. + /// The format of the message object to log. + /// The exception to log. + /// + public virtual void WarnFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new StringFormatFormattedMessage(formatProvider, format, args), exception); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + public virtual void WarnFormat(string format, params object[] args) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new StringFormatFormattedMessage(null, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + public virtual void WarnFormat(string format, Exception exception, params object[] args) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new StringFormatFormattedMessage(null, format, args), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Warn(FormatMessageCallback formatMessageCallback) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Warn. + public virtual void Warn(FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Warn. + public virtual void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); + } + + #endregion + + #region Error + + /// + /// Log a message object with the level. + /// + /// The message object to log. + public virtual void Error(object message) + { + if (IsErrorEnabled) + Write(LogLevel.Error, message, null); + } + + /// + /// Log a message object with the level including + /// the stack Error of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack Error. + public virtual void Error(object message, Exception exception) + { + if (IsErrorEnabled) + Write(LogLevel.Error, message, exception); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Errorrmation. + /// The format of the message object to log. + /// + public virtual void ErrorFormat(IFormatProvider formatProvider, string format, params object[] args) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new StringFormatFormattedMessage(formatProvider, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Errorrmation. + /// The format of the message object to log. + /// The exception to log. + /// + public virtual void ErrorFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new StringFormatFormattedMessage(formatProvider, format, args), exception); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + public virtual void ErrorFormat(string format, params object[] args) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new StringFormatFormattedMessage(null, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + public virtual void ErrorFormat(string format, Exception exception, params object[] args) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new StringFormatFormattedMessage(null, format, args), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Error(FormatMessageCallback formatMessageCallback) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Error. + public virtual void Error(FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Error. + public virtual void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); + } + + #endregion + + #region Fatal + + /// + /// Log a message object with the level. + /// + /// The message object to log. + public virtual void Fatal(object message) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, message, null); + } + + /// + /// Log a message object with the level including + /// the stack Fatal of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack Fatal. + public virtual void Fatal(object message, Exception exception) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, message, exception); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Fatalrmation. + /// The format of the message object to log. + /// + public virtual void FatalFormat(IFormatProvider formatProvider, string format, params object[] args) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new StringFormatFormattedMessage(formatProvider, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Fatalrmation. + /// The format of the message object to log. + /// The exception to log. + /// + public virtual void FatalFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new StringFormatFormattedMessage(formatProvider, format, args), exception); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + public virtual void FatalFormat(string format, params object[] args) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new StringFormatFormattedMessage(null, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + public virtual void FatalFormat(string format, Exception exception, params object[] args) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new StringFormatFormattedMessage(null, format, args), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Fatal(FormatMessageCallback formatMessageCallback) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + public virtual void Fatal(FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + public virtual void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/NamespaceDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/NamespaceDoc.cs new file mode 100644 index 0000000..8eef63d --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/NamespaceDoc.cs @@ -0,0 +1,31 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 + +namespace Common.Logging.Factory +{ + /// + /// This namespace contains convenience base classes for implementing your own s. + /// + [CoverageExclude] + internal static class NamespaceDoc + { + // serves as namespace summary for NDoc3 (http://ndoc3.sourceforge.net) + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/FormatMessageHandler.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/FormatMessageHandler.cs new file mode 100644 index 0000000..5f6babc --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/FormatMessageHandler.cs @@ -0,0 +1,32 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 + +namespace Common.Logging +{ + /// + /// The type of method that is passed into e.g. + /// and allows the callback method to "submit" it's message to the underlying output system. + /// + ///the format argument as in + ///the argument list as in + /// + /// Erich Eichinger + public delegate string FormatMessageHandler(string format, params object[] args); +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/IConfigurationReader.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/IConfigurationReader.cs new file mode 100644 index 0000000..2822a08 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/IConfigurationReader.cs @@ -0,0 +1,49 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Configuration; + +namespace Common.Logging +{ + + /// + /// Interface for basic operations to read .NET application configuration information. + /// + /// Provides a simple abstraction to handle BCL API differences between .NET 1.x and 2.0. Also + /// useful for testing scenarios. + /// Mark Pollack + public interface IConfigurationReader + { + /// + /// Parses the configuration section and returns the resulting object. + /// + /// + ///

+ /// Primary purpose of this method is to allow us to parse and + /// load configuration sections using the same API regardless + /// of the .NET framework version. + ///

+ ///
+ /// Name of the configuration section. + /// Object created by a corresponding . + /// + object GetSection(string sectionName); + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILog.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILog.cs new file mode 100644 index 0000000..6869265 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILog.cs @@ -0,0 +1,649 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 FormatMessageCallback = System.Action; + +namespace Common.Logging +{ + /// + /// A simple logging interface abstracting logging APIs. + /// + /// + /// + /// Implementations should defer calling a message's until the message really needs + /// to be logged to avoid performance penalties. + /// + /// + /// Each log method offers to pass in a instead of the actual message. + /// Using this style has the advantage to defer possibly expensive message argument evaluation and formatting (and formatting arguments!) until the message gets + /// actually logged. If the message is not logged at all (e.g. due to settings), + /// you won't have to pay the peformance penalty of creating the message. + /// + /// + /// + /// The example below demonstrates using callback style for creating the message, where the call to the + /// and the underlying only happens, if level is enabled: + /// + /// Log.Debug( m=>m("result is {0}", random.NextDouble()) ); + /// Log.Debug(delegate(m) { m("result is {0}", random.NextDouble()); }); + /// + /// + /// + /// Mark Pollack + /// Bruno Baia + /// Erich Eichinger + public interface ILog + { + /// + /// Log a message object with the level. + /// + /// The message object to log. + void Trace(object message); + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + void Trace(object message, Exception exception); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + void TraceFormat(string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + void TraceFormat(string format, Exception exception, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + void TraceFormat(IFormatProvider formatProvider, string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + void TraceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + void Trace(FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Trace(FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message object with the level. + /// + /// The message object to log. + void Debug( object message ); + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + void Debug( object message, Exception exception ); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + void DebugFormat(string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + void DebugFormat(string format, Exception exception, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + void DebugFormat(IFormatProvider formatProvider, string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + void DebugFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + void Debug(FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Debug(FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Debug. + void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message object with the level. + /// + /// The message object to log. + void Info(object message); + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + void Info(object message, Exception exception); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + void InfoFormat(string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + void InfoFormat(string format, Exception exception, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + void InfoFormat(IFormatProvider formatProvider, string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + void InfoFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + void Info(FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Info(FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Info. + void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message object with the level. + /// + /// The message object to log. + void Warn(object message); + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + void Warn(object message, Exception exception); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + void WarnFormat(string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + void WarnFormat(string format, Exception exception, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + void WarnFormat(IFormatProvider formatProvider, string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + void WarnFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + void Warn(FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Warn(FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Warn. + void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message object with the level. + /// + /// The message object to log. + void Error( object message ); + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + void Error( object message, Exception exception ); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + void ErrorFormat(string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + void ErrorFormat(string format, Exception exception, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + void ErrorFormat(IFormatProvider formatProvider, string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + void ErrorFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + void Error(FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Error(FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Error. + void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message object with the level. + /// + /// The message object to log. + void Fatal( object message ); + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + void Fatal( object message, Exception exception ); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + void FatalFormat(string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + void FatalFormat(string format, Exception exception, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + void FatalFormat(IFormatProvider formatProvider, string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + void FatalFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + void Fatal(FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Fatal(FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Checks if this logger is enabled for the level. + /// + bool IsTraceEnabled + { + get; + } + + /// + /// Checks if this logger is enabled for the level. + /// + bool IsDebugEnabled + { + get; + } + + /// + /// Checks if this logger is enabled for the level. + /// + bool IsErrorEnabled + { + get; + } + + /// + /// Checks if this logger is enabled for the level. + /// + bool IsFatalEnabled + { + get; + } + + /// + /// Checks if this logger is enabled for the level. + /// + bool IsInfoEnabled + { + get; + } + + /// + /// Checks if this logger is enabled for the level. + /// + bool IsWarnEnabled + { + get; + } + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILoggerFactoryAdapter.cs new file mode 100644 index 0000000..524bc52 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILoggerFactoryAdapter.cs @@ -0,0 +1,49 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 Common.Logging +{ + /// + /// LoggerFactoryAdapter interface is used internally by LogManager + /// Only developers wishing to write new Common.Logging adapters need to + /// worry about this interface. + /// + /// Gilles Bayon + public interface ILoggerFactoryAdapter + { + + /// + /// Get a ILog instance by type. + /// + /// The type to use for the logger + /// + ILog GetLogger( Type type ); + + /// + /// Get a ILog instance by name. + /// + /// The name of the logger + /// + ILog GetLogger( string name ); + + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogLevel.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogLevel.cs new file mode 100644 index 0000000..f1ad189 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogLevel.cs @@ -0,0 +1,62 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 + +namespace Common.Logging +{ + /// + /// The 7 possible logging levels + /// + /// Gilles Bayon + public enum LogLevel + { + /// + /// All logging levels + /// + All = 0, + /// + /// A trace logging level + /// + Trace = 1, + /// + /// A debug logging level + /// + Debug = 2, + /// + /// A info logging level + /// + Info = 3, + /// + /// A warn logging level + /// + Warn = 4, + /// + /// An error logging level + /// + Error = 5, + /// + /// A fatal logging level + /// + Fatal = 6, + /// + /// Do not log anything. + /// + Off = 7, + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogManager.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogManager.cs new file mode 100644 index 0000000..4ba8d98 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogManager.cs @@ -0,0 +1,333 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Configuration; +using System.Diagnostics; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Security; +using System.Security.Permissions; +using Common.Logging.Simple; +using Common.Logging.Configuration; + +namespace Common.Logging +{ + /// + /// Use the LogManager's or + /// methods to obtain instances for logging. + /// + /// + /// For configuring the underlying log system using application configuration, see the example + /// at . + /// For configuring programmatically, see the example section below. + /// + /// + /// The example below shows the typical use of LogManager to obtain a reference to a logger + /// and log an exception: + /// + /// + /// ILog log = LogManager.GetLogger(this.GetType()); + /// ... + /// try + /// { + /// /* .... */ + /// } + /// catch(Exception ex) + /// { + /// log.ErrorFormat("Hi {0}", ex, "dude"); + /// } + /// + /// + /// The example below shows programmatic configuration of the underlying log system: + /// + /// + /// // create properties + /// NameValueCollection properties = new NameValueCollection(); + /// properties["showDateTime"] = "true"; + /// + /// // set Adapter + /// Common.Logging.LogManager.Adapter = new + /// Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(properties); + /// + /// + /// + /// + /// + /// + /// + /// Gilles Bayon + public static class LogManager + { + /// + /// The name of the default configuration section to read settings from. + /// + /// + /// You can always change the source of your configuration settings by setting another instance + /// on . + /// + public static readonly string COMMON_LOGGING_SECTION = "Settings.bundle/Common.Logging.plist"; + + private static IConfigurationReader _configurationReader; + private static ILoggerFactoryAdapter _adapter; + private static readonly object _loadLock = new object(); + + /// + /// Performs static 1-time init of LogManager by calling + /// + static LogManager() + { + Reset(); + } + + /// + /// Reset the infrastructure to its default settings. This means, that configuration settings + /// will be re-read from section <common/logging> of your app.config. + /// + /// + /// This is mainly used for unit testing, you wouldn't normally use this in your applications.
+ /// Note: instances already handed out from this LogManager are not(!) affected. + /// Resetting LogManager only affects new instances being handed out. + ///
+ public static void Reset() + { + Reset(new MonoTouchConfigurationReader()); + } + + /// + /// Reset the infrastructure to its default settings. This means, that configuration settings + /// will be re-read from section <common/logging> of your app.config. + /// + /// + /// This is mainly used for unit testing, you wouldn't normally use this in your applications.
+ /// Note: instances already handed out from this LogManager are not(!) affected. + /// Resetting LogManager only affects new instances being handed out. + ///
+ /// + /// the instance to obtain settings for + /// re-initializing the LogManager. + /// + public static void Reset(IConfigurationReader reader) + { + lock (_loadLock) + { + if (reader == null) + { + throw new ArgumentNullException("reader"); + } + _configurationReader = reader; + _adapter = null; + } + } + + /// + /// Gets the configuration reader used to initialize the LogManager. + /// + /// Primarily used for testing purposes but maybe useful to obtain configuration + /// information from some place other than the .NET application configuration file. + /// The configuration reader. + public static IConfigurationReader ConfigurationReader + { + get + { + return _configurationReader; + } + } + + /// + /// Gets or sets the adapter. + /// + /// The adapter. + public static ILoggerFactoryAdapter Adapter + { + get + { + if (_adapter == null) + { + lock (_loadLock) + { + if (_adapter == null) + { + _adapter = BuildLoggerFactoryAdapter(); + } + } + } + return _adapter; + } + set + { + if (value == null) + { + throw new ArgumentNullException("Adapter"); + } + + lock (_loadLock) + { + _adapter = value; + } + } + } + + /// + /// Gets the logger by calling + /// on the currently configured using the type of the calling class. + /// + /// + /// This method needs to inspect the in order to determine the calling + /// class. This of course comes with a performance penalty, thus you shouldn't call it too + /// often in your application. + /// + /// + /// the logger instance obtained from the current + [MethodImpl(MethodImplOptions.NoInlining)] + public static ILog GetCurrentClassLogger() + { + StackFrame frame = new StackFrame(1, false); + ILoggerFactoryAdapter adapter = Adapter; + MethodBase method = frame.GetMethod(); + Type declaringType = method.DeclaringType; + return adapter.GetLogger(declaringType); + } + + /// + /// Gets the logger by calling + /// on the currently configured using the specified type. + /// + /// the logger instance obtained from the current + public static ILog GetLogger() + { + return Adapter.GetLogger(typeof(T)); + } + + /// + /// Gets the logger by calling + /// on the currently configured using the specified type. + /// + /// The type. + /// the logger instance obtained from the current + public static ILog GetLogger(Type type) + { + return Adapter.GetLogger(type); + } + + + /// + /// Gets the logger by calling + /// on the currently configured using the specified name. + /// + /// The name. + /// the logger instance obtained from the current + public static ILog GetLogger(string name) + { + return Adapter.GetLogger(name); + } + + + /// + /// Builds the logger factory adapter. + /// + /// a factory adapter instance. Is never null. + private static ILoggerFactoryAdapter BuildLoggerFactoryAdapter() + { + object sectionResult = null; + + ArgUtils.Guard(delegate + { + sectionResult = ConfigurationReader.GetSection(COMMON_LOGGING_SECTION); + } + , "Failed obtaining configuration for Common.Logging from configuration section 'common/logging'."); + + // configuration reader returned + if (sectionResult == null) + { + string message = (ConfigurationReader.GetType() == typeof(MonoTouchConfigurationReader)) + ? string.Format("no configuration plist <{0}> found - suppressing logging output", COMMON_LOGGING_SECTION) + : string.Format("Custom ConfigurationReader '{0}' returned - suppressing logging output", ConfigurationReader.GetType().FullName); + Console.Error.WriteLine(message); + ILoggerFactoryAdapter defaultFactory = new NoOpLoggerFactoryAdapter(); + return defaultFactory; + } + + // ready to use ILoggerFactoryAdapter? + if (sectionResult is ILoggerFactoryAdapter) + { + Console.Error.WriteLine(string.Format("Using ILoggerFactoryAdapter returned from custom ConfigurationReader '{0}'", ConfigurationReader.GetType().FullName)); + return (ILoggerFactoryAdapter)sectionResult; + } + + // ensure what's left is a LogSetting instance + ArgUtils.Guard(delegate + { + ArgUtils.AssertIsAssignable("sectionResult", sectionResult.GetType()); + } + , "ConfigurationReader {0} returned unknown settings instance of type {1}" + , ConfigurationReader.GetType().FullName, sectionResult.GetType().FullName); + + ILoggerFactoryAdapter adapter = null; + ArgUtils.Guard(delegate + { + adapter = BuildLoggerFactoryAdapterFromLogSettings((LogSetting)sectionResult); + } + , "Failed creating LoggerFactoryAdapter from settings"); + + return adapter; + } + + /// + /// Builds a instance from the given + /// using . + /// + /// + /// the instance. Is never null + private static ILoggerFactoryAdapter BuildLoggerFactoryAdapterFromLogSettings(LogSetting setting) + { + ArgUtils.AssertNotNull("setting", setting); + // already ensured by LogSetting + // AssertArgIsAssignable("setting.FactoryAdapterType", setting.FactoryAdapterType + // , "Specified FactoryAdapter does not implement {0}. Check implementation of class {1}" + // , typeof(ILoggerFactoryAdapter).FullName + // , setting.FactoryAdapterType.AssemblyQualifiedName); + + ILoggerFactoryAdapter adapter = null; + + ArgUtils.Guard(delegate + { + if (setting.Properties != null + && setting.Properties.Count > 0) + { + object[] args = { setting.Properties }; + + adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType, args); + } + else + { + adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType); + } + } + , "Unable to create instance of type {0}. Possible explanation is lack of zero arg and single arg NameValueCollection constructors" + , setting.FactoryAdapterType.FullName + ); + + // make sure + ArgUtils.AssertNotNull("adapter", adapter, "Activator.CreateInstance() returned "); + return adapter; + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/MonoNet/CollectionsUtil.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/MonoNet/CollectionsUtil.cs new file mode 100644 index 0000000..c570861 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/MonoNet/CollectionsUtil.cs @@ -0,0 +1,64 @@ +// +// System.Collections.Specialized.CollectionsUtil.cs +// +// Author: +// Lawrence Pit (loz@cable.a2000.nl) +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System.Collections; + +namespace System.Collections.Specialized { + +#if !NET_2_1 + public +#else + internal +#endif + class CollectionsUtil { + + public CollectionsUtil () {} + + public static Hashtable CreateCaseInsensitiveHashtable () + { + return new Hashtable (CaseInsensitiveHashCodeProvider.Default, + CaseInsensitiveComparer.Default); + } + + + public static Hashtable CreateCaseInsensitiveHashtable (IDictionary d) { + return new Hashtable (d, CaseInsensitiveHashCodeProvider.Default, + CaseInsensitiveComparer.Default); + } + + public static Hashtable CreateCaseInsensitiveHashtable (int capacity) { + return new Hashtable (capacity, CaseInsensitiveHashCodeProvider.Default, + CaseInsensitiveComparer.Default); + } + + + public static SortedList CreateCaseInsensitiveSortedList () { + return new SortedList (CaseInsensitiveComparer.Default); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/NamespaceDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/NamespaceDoc.cs new file mode 100644 index 0000000..8548947 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/NamespaceDoc.cs @@ -0,0 +1,31 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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 + +namespace Common.Logging +{ + /// + /// This namespace contains all core classes making up the Common.Logging framework. + /// + [CoverageExclude] + internal static class NamespaceDoc + { + // serves as namespace summary for NDoc3 (http://ndoc3.sourceforge.net) + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLogger.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLogger.cs new file mode 100644 index 0000000..fb541ed --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLogger.cs @@ -0,0 +1,263 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Globalization; +using System.Text; +using Common.Logging.Factory; + +namespace Common.Logging.Simple +{ + /// + /// Abstract class providing a standard implementation of simple loggers. + /// + /// Erich Eichinger + [Serializable] + public abstract class AbstractSimpleLogger : AbstractLogger + { + private readonly string _name; + private readonly bool _showLevel; + private readonly bool _showDateTime; + private readonly bool _showLogName; + private LogLevel _currentLogLevel; + private readonly string _dateTimeFormat; + private readonly bool _hasDateTimeFormat; + + #region Properties + + /// + /// The name of the logger. + /// + [CoverageExclude] + public string Name + { + get { return _name; } + } + + /// + /// Include the current log level in the log message. + /// + [CoverageExclude] + public bool ShowLevel + { + get { return _showLevel; } + } + + /// + /// Include the current time in the log message. + /// + [CoverageExclude] + public bool ShowDateTime + { + get { return _showDateTime; } + } + + /// + /// Include the instance name in the log message. + /// + [CoverageExclude] + public bool ShowLogName + { + get { return _showLogName; } + } + + /// + /// The current logging threshold. Messages recieved that are beneath this threshold will not be logged. + /// + [CoverageExclude] + public LogLevel CurrentLogLevel + { + get { return _currentLogLevel; } + set { _currentLogLevel = value; } + } + + /// + /// The date and time format to use in the log message. + /// + [CoverageExclude] + public string DateTimeFormat + { + get { return _dateTimeFormat; } + } + + /// + /// Determines Whether is set. + /// + [CoverageExclude] + public bool HasDateTimeFormat + { + get { return _hasDateTimeFormat; } + } + + + #endregion + + /// + /// Creates and initializes a the simple logger. + /// + /// The name, usually type name of the calling class, of the logger. + /// The current logging threshold. Messages recieved that are beneath this threshold will not be logged. + /// Include level in the log message. + /// Include the current time in the log message. + /// Include the instance name in the log message. + /// The date and time format to use in the log message. + public AbstractSimpleLogger(string logName, LogLevel logLevel, bool showlevel + , bool showDateTime, bool showLogName, string dateTimeFormat) + { + _name = logName; + _currentLogLevel = logLevel; + _showLevel = showlevel; + _showDateTime = showDateTime; + _showLogName = showLogName; + _dateTimeFormat = dateTimeFormat; + _hasDateTimeFormat = (!string.IsNullOrEmpty(_dateTimeFormat)); + } + + /// + /// Appends the formatted message to the specified . + /// + /// the that receíves the formatted message. + /// + /// + /// + protected virtual void FormatOutput(StringBuilder stringBuilder, LogLevel level, object message, Exception e) + { + if (stringBuilder == null) + { + throw new ArgumentNullException("stringBuilder"); + } + + // Append date-time if so configured + if (_showDateTime) + { + if (_hasDateTimeFormat) + { + stringBuilder.Append(DateTime.Now.ToString(_dateTimeFormat, CultureInfo.InvariantCulture)); + } + else + { + stringBuilder.Append(DateTime.Now); + } + + stringBuilder.Append(" "); + } + + if (_showLevel) + { + // Append a readable representation of the log level + stringBuilder.Append(("[" + level.ToString().ToUpper() + "]").PadRight(8)); + } + + // Append the name of the log instance if so configured + if (_showLogName) + { + stringBuilder.Append(_name).Append(" - "); + } + + // Append the message + stringBuilder.Append(message); + + // Append stack trace if not null + if (e != null) + { + stringBuilder.Append(Environment.NewLine).Append(e.ToString()); + } + } + + /// + /// Determines if the given log level is currently enabled. + /// + /// + /// + protected virtual bool IsLevelEnabled(LogLevel level) + { + int iLevel = (int)level; + int iCurrentLogLevel = (int)_currentLogLevel; + + // return iLevel.CompareTo(iCurrentLogLevel); better ??? + return (iLevel >= iCurrentLogLevel); + } + + #region ILog Members + + /// + /// Returns if the current is greater than or + /// equal to . If it is, all messages will be sent to . + /// + public override bool IsTraceEnabled + { + get { return IsLevelEnabled(LogLevel.Trace); } + } + + /// + /// Returns if the current is greater than or + /// equal to . If it is, all messages will be sent to . + /// + public override bool IsDebugEnabled + { + get { return IsLevelEnabled(LogLevel.Debug); } + } + + /// + /// Returns if the current is greater than or + /// equal to . If it is, only messages with a of + /// , , , and + /// will be sent to . + /// + public override bool IsInfoEnabled + { + get { return IsLevelEnabled(LogLevel.Info); } + } + + + /// + /// Returns if the current is greater than or + /// equal to . If it is, only messages with a of + /// , , and + /// will be sent to . + /// + public override bool IsWarnEnabled + { + get { return IsLevelEnabled(LogLevel.Warn); } + } + + /// + /// Returns if the current is greater than or + /// equal to . If it is, only messages with a of + /// and will be sent to . + /// + public override bool IsErrorEnabled + { + get { return IsLevelEnabled(LogLevel.Error); } + } + + /// + /// Returns if the current is greater than or + /// equal to . If it is, only messages with a of + /// will be sent to . + /// + public override bool IsFatalEnabled + { + get { return IsLevelEnabled(LogLevel.Fatal); } + } + + #endregion + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs new file mode 100644 index 0000000..f2a36f9 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs @@ -0,0 +1,168 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Collections.Specialized; +using Common.Logging.Factory; + +namespace Common.Logging.Simple +{ + /// + /// Base factory implementation for creating simple instances. + /// + /// Default settings are LogLevel.All, showDateTime = true, showLogName = true, and no DateTimeFormat. + /// The keys in the NameValueCollection to configure this adapter are the following + /// + /// level + /// showDateTime + /// showLogName + /// dateTimeFormat + /// + /// + /// Here is an example how to implement your own logging adapter: + /// + /// public class ConsoleOutLogger : AbstractSimpleLogger + /// { + /// public ConsoleOutLogger(string logName, LogLevel logLevel, bool showLevel, bool showDateTime, + /// bool showLogName, string dateTimeFormat) + /// : base(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat) + /// { + /// } + /// + /// protected override void WriteInternal(LogLevel level, object message, Exception e) + /// { + /// // Use a StringBuilder for better performance + /// StringBuilder sb = new StringBuilder(); + /// FormatOutput(sb, level, message, e); + /// + /// // Print to the appropriate destination + /// Console.Out.WriteLine(sb.ToString()); + /// } + /// } + /// + /// public class ConsoleOutLoggerFactoryAdapter : AbstractSimpleLoggerFactoryAdapter + /// { + /// public ConsoleOutLoggerFactoryAdapter(NameValueCollection properties) + /// : base(properties) + /// { } + /// + /// protected override ILog CreateLogger(string name, LogLevel level, bool showLevel, bool + /// showDateTime, bool showLogName, string dateTimeFormat) + /// { + /// ILog log = new ConsoleOutLogger(name, level, showLevel, showDateTime, showLogName, + /// dateTimeFormat); + /// return log; + /// } + /// } + /// + /// + /// + /// + /// + /// Gilles Bayon + /// Mark Pollack + /// Erich Eichinger + public abstract class AbstractSimpleLoggerFactoryAdapter : AbstractCachingLoggerFactoryAdapter + { + private LogLevel _level; + private bool _showLevel; + private bool _showDateTime; + private bool _showLogName; + private string _dateTimeFormat; + + /// + /// The default to use when creating new instances. + /// + [CoverageExclude] + public LogLevel Level + { + get { return _level; } + set { _level = value; } + } + + /// + /// The default setting to use when creating new instances. + /// + [CoverageExclude] + public bool ShowLevel + { + get { return _showLevel; } + set { _showLevel = value; } + } + + /// + /// The default setting to use when creating new instances. + /// + [CoverageExclude] + public bool ShowDateTime + { + get { return _showDateTime; } + set { _showDateTime = value; } + } + + /// + /// The default setting to use when creating new instances. + /// + [CoverageExclude] + public bool ShowLogName + { + get { return _showLogName; } + set { _showLogName = value; } + } + + /// + /// The default setting to use when creating new instances. + /// + [CoverageExclude] + public string DateTimeFormat + { + get { return _dateTimeFormat; } + set { _dateTimeFormat = value; } + } + + /// + /// Initializes a new instance of the class with + /// default settings for the loggers created by this factory. + /// + protected AbstractSimpleLoggerFactoryAdapter(LogLevel level, bool showDateTime, bool showLogName, bool showLevel, string dateTimeFormat) + :base(true) + { + _level = level; + _showDateTime = showDateTime; + _showLogName = showLogName; + _showLevel = showLevel; + _dateTimeFormat = dateTimeFormat ?? string.Empty; + } + + /// + /// Create the specified logger instance + /// + protected override ILog CreateLogger(string name) + { + return CreateLogger(name, _level, _showLevel, _showDateTime, _showLogName, _dateTimeFormat); + } + + /// + /// Derived factories need to implement this method to create the + /// actual logger instance. + /// + /// a new logger instance. Must never be null! + protected abstract ILog CreateLogger(string name, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat); + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLogger.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLogger.cs new file mode 100644 index 0000000..735e35f --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLogger.cs @@ -0,0 +1,64 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 Common.Logging.Simple +{ + /// + /// Sends log messages to . + /// + /// Gilles Bayon + [Serializable] + public class ConsoleOutLogger : AbstractSimpleLogger + { + /// + /// Creates and initializes a logger that writes messages to . + /// + /// The name, usually type name of the calling class, of the logger. + /// The current logging threshold. Messages recieved that are beneath this threshold will not be logged. + /// Include the current log level in the log message. + /// Include the current time in the log message. + /// Include the instance name in the log message. + /// The date and time format to use in the log message. + public ConsoleOutLogger(string logName, LogLevel logLevel, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) + : base(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat) + { + } + + /// + /// Do the actual logging by constructing the log message using a then + /// sending the output to . + /// + /// The of the message. + /// The log message. + /// An optional associated with the message. + protected override void WriteInternal(LogLevel level, object message, Exception e) + { + // Use a StringBuilder for better performance + StringBuilder sb = new StringBuilder(); + FormatOutput(sb, level, message, e); + + // Print to the appropriate destination + Console.Out.WriteLine(sb.ToString()); + } + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs new file mode 100644 index 0000000..02b5455 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs @@ -0,0 +1,81 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 Common.Logging.Simple +{ + /// + /// Factory for creating instances that write data to . + /// + /// + /// + /// Below is an example how to configure this adapter: + /// + /// <configuration> + /// + /// <configSections> + /// <sectionGroup name="common"> + /// <section name="logging" + /// type="Common.Logging.ConfigurationSectionHandler, Common.Logging" + /// requirePermission="false" /> + /// </sectionGroup> + /// </configSections> + /// + /// <common> + /// <logging> + /// <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging"> + /// <arg key="level" value="ALL" /> + /// </factoryAdapter> + /// </logging> + /// </common> + /// + /// </configuration> + /// + /// + /// + /// + /// + /// + /// Gilles Bayon + /// Mark Pollack + /// Erich Eichinger + public class ConsoleOutLoggerFactoryAdapter : AbstractSimpleLoggerFactoryAdapter + { + + /// + /// Initializes a new instance of the class with + /// default settings for the loggers created by this factory. + /// + public ConsoleOutLoggerFactoryAdapter(LogLevel level, bool showDateTime, bool showLogName, bool showLevel, string dateTimeFormat) + : base(level, showDateTime, showLogName, showLevel, dateTimeFormat) + { } + + /// + /// Creates a new instance. + /// + protected override ILog CreateLogger(string name, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) + { + ILog log = new ConsoleOutLogger(name, level, showLevel, showDateTime, showLogName, dateTimeFormat); + return log; + } + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NamespaceDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NamespaceDoc.cs new file mode 100644 index 0000000..99ff197 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NamespaceDoc.cs @@ -0,0 +1,31 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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 + +namespace Common.Logging.Simple +{ + /// + /// This namespace contains all core classes making up the Common.Logging framework. + /// + [CoverageExclude] + internal static class NamespaceDoc + { + // serves as namespace summary for NDoc3 (http://ndoc3.sourceforge.net) + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLogger.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLogger.cs new file mode 100644 index 0000000..3d5f287 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLogger.cs @@ -0,0 +1,731 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 FormatMessageCallback = System.Action; + +namespace Common.Logging.Simple +{ + /// + /// Silently ignores all log messages. + /// + /// Gilles Bayon + /// Erich Eichinger + [Serializable] + [CoverageExclude] + public sealed class NoOpLogger : ILog + { + #region IsXXXEnabled + + /// + /// Always returns . + /// + public bool IsTraceEnabled + { + get { return false; } + } + + /// + /// Always returns . + /// + public bool IsDebugEnabled + { + get { return false; } + } + + /// + /// Always returns . + /// + public bool IsInfoEnabled + { + get { return false; } + } + + /// + /// Always returns . + /// + public bool IsWarnEnabled + { + get { return false; } + } + + /// + /// Always returns . + /// + public bool IsErrorEnabled + { + get { return false; } + + } + + /// + /// Always returns . + /// + public bool IsFatalEnabled + { + get { return false; } + } + + #endregion + + #region Trace + + /// + /// Ignores message. + /// + /// + public void Trace(object message) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// + /// + public void Trace(object message, Exception e) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// + public void TraceFormat(string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void TraceFormat(string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// the list of message format arguments + public void TraceFormat(IFormatProvider formatProvider, string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void TraceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + public void Trace(FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + public void Trace(FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + public void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + #endregion + + #region Debug + + /// + /// Ignores message. + /// + /// + public void Debug(object message) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// + /// + public void Debug(object message, Exception e) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// + public void DebugFormat(string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void DebugFormat(string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// the list of message format arguments + public void DebugFormat(IFormatProvider formatProvider, string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void DebugFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + public void Debug(FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Debug. + public void Debug(FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Debug. + public void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + #endregion + + #region Info + + /// + /// Ignores message. + /// + /// + public void Info(object message) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// + /// + public void Info(object message, Exception e) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// + public void InfoFormat(string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void InfoFormat(string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// the list of message format arguments + public void InfoFormat(IFormatProvider formatProvider, string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void InfoFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + public void Info(FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Info. + public void Info(FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Info. + public void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + #endregion + + #region Warn + + /// + /// Ignores message. + /// + /// + public void Warn(object message) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// + /// + public void Warn(object message, Exception e) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// + public void WarnFormat(string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void WarnFormat(string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Warnrmation. + /// The format of the message object to log. + /// the list of message format arguments + public void WarnFormat(IFormatProvider formatProvider, string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Warnrmation. + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void WarnFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + public void Warn(FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Warn. + public void Warn(FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Warn. + public void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + #endregion + + #region Error + + /// + /// Ignores message. + /// + /// + public void Error(object message) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// + /// + public void Error(object message, Exception e) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// + public void ErrorFormat(string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void ErrorFormat(string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Errorrmation. + /// The format of the message object to log. + /// the list of message format arguments + public void ErrorFormat(IFormatProvider formatProvider, string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Errorrmation. + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void ErrorFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + public void Error(FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Error. + public void Error(FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Error. + public void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + #endregion + + #region Fatal + + /// + /// Ignores message. + /// + /// + public void Fatal(object message) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// + /// + public void Fatal(object message, Exception e) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// + public void FatalFormat(string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void FatalFormat(string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Fatalrmation. + /// The format of the message object to log. + /// the list of message format arguments + public void FatalFormat(IFormatProvider formatProvider, string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Fatalrmation. + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void FatalFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + public void Fatal(FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + public void Fatal(FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + public void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + #endregion + + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLoggerFactoryAdapter.cs new file mode 100644 index 0000000..d1aa14b --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLoggerFactoryAdapter.cs @@ -0,0 +1,102 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 Common.Logging.Simple +{ + /// + /// Factory for creating instances that silently ignores + /// logging requests. + /// + /// + /// This logger adapter is the default used by Common.Logging if unconfigured. Using this logger adapter is the most efficient + /// way to suppress any logging output. + /// + /// Below is an example how to configure this adapter: + /// + /// <configuration> + /// + /// <configSections> + /// <sectionGroup name="common"> + /// <section name="logging" + /// type="Common.Logging.ConfigurationSectionHandler, Common.Logging" + /// requirePermission="false" /> + /// </sectionGroup> + /// </configSections> + /// + /// <common> + /// <logging> + /// <factoryAdapter type="Common.Logging.Simple.NoOpLoggerFactoryAdapter, Common.Logging"> + /// <arg key="level" value="ALL" /> + /// </factoryAdapter> + /// </logging> + /// </common> + /// + /// </configuration> + /// + /// + /// + /// + /// + /// Gilles Bayon + public sealed class NoOpLoggerFactoryAdapter : ILoggerFactoryAdapter + { + private static readonly ILog s_nopLogger = new NoOpLogger(); + + /// + /// Constructor + /// + public NoOpLoggerFactoryAdapter() + { } + + /// + /// Constructor + /// + public NoOpLoggerFactoryAdapter(NameValueCollection properties) + { } + + #region ILoggerFactoryAdapter Members + + /// + /// Get a ILog instance by type + /// + /// + /// + public ILog GetLogger(Type type) + { + return s_nopLogger; + } + + /// + /// Get a ILog instance by type name + /// + /// + /// + ILog ILoggerFactoryAdapter.GetLogger(string name) + { + return s_nopLogger; + + } + + #endregion + } +} diff --git a/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs b/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs index 6a941c1..e033eb2 100644 --- a/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs +++ b/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs @@ -19,7 +19,7 @@ #endregion using System.Collections.Specialized; -using System.Configuration; +using namespace Common.Logging.Configuration { diff --git a/src/Common.Logging/Logging/IConfigurationReader.cs b/src/Common.Logging/Logging/IConfigurationReader.cs index 2822a08..52dd1c1 100644 --- a/src/Common.Logging/Logging/IConfigurationReader.cs +++ b/src/Common.Logging/Logging/IConfigurationReader.cs @@ -18,8 +18,6 @@ #endregion -using System.Configuration; - namespace Common.Logging { diff --git a/src/CommonAssemblyInfo.cs b/src/CommonAssemblyInfo.cs index 2e686b2..6502561 100644 --- a/src/CommonAssemblyInfo.cs +++ b/src/CommonAssemblyInfo.cs @@ -22,7 +22,7 @@ [assembly: AssemblyTrademarkAttribute("Apache License, Version 2.0")] [assembly: AssemblyCultureAttribute("")] [assembly: AssemblyVersionAttribute("2.1.2")] -[assembly: AssemblyConfigurationAttribute("net-4.0.win32; release")] -[assembly: AssemblyInformationalVersionAttribute("2.1.2; net-4.0.win32; release")] +[assembly: AssemblyConfigurationAttribute("monotouch; release")] +[assembly: AssemblyInformationalVersionAttribute("2.1.2; monotouch; release")] [assembly: AssemblyDelaySignAttribute(false)] From e196e6d2a524d325502e8f30e06e06c3570d4b35 Mon Sep 17 00:00:00 2001 From: adamnation Date: Sat, 26 Jan 2013 12:38:11 -0800 Subject: [PATCH 03/12] ported unit tests and unit test utils to monotouch, monotouch logger tests pass --- .DS_Store | Bin 0 -> 6148 bytes Common.Logging.2010-net40.userprefs | 20 +++ .../Common.Logging.MonoTouch/.DS_Store | Bin 0 -> 6148 bytes .../Common.Logging.MonoTouch.Tests.csproj | 117 +++++++++++++ .../Common.Logging.MonoTouch.Tests/Info.plist | 26 +++ .../SImple/AbstractSimpleLoggerTests.cs | 98 +++++++++++ .../SImple/AbstractSimpleLoggerTestsBase.cs | 46 +++++ .../Logging/SImple/ConsoleOutLoggerTests.cs | 56 +++++++ .../Common.Logging.MonoTouch.Tests/Main.cs | 20 +++ .../Settings.bundle/Common.Logging | 6 + .../Settings.bundle/Common.Logging.plist | 18 ++ .../Settings.bundle/Root.plist | 62 +++++++ .../UnitTestAppDelegate.cs | 46 +++++ .../Common.Logging.MonoTouch.sln | 42 +++++ .../Common.Logging.MonoTouch.userprefs | 20 +++ .../MonoTouchConfigurationReader.cs | 15 +- .../AbstractSimpleLoggerFactoryAdapter.cs | 23 +++ .../Simple/ConsoleOutLoggerFactoryAdapter.cs | 133 +++++++++------ .../Common.Logging.TestUtlis.MonoTouch.csproj | 55 ++++++ .../Logging/ILogTestsBase.cs | 158 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 35 ++++ .../TestUtil/SerializationTestUtils.cs | 135 +++++++++++++++ .../TestUtil/TraceEventArgs.cs | 54 ++++++ .../DefaultConfigurationReader.cs | 2 +- 24 files changed, 1128 insertions(+), 59 deletions(-) create mode 100644 .DS_Store create mode 100644 Common.Logging.2010-net40.userprefs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/.DS_Store create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Info.plist create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTestsBase.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/ConsoleOutLoggerTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Main.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Root.plist create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/UnitTestAppDelegate.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.userprefs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Common.Logging.TestUtlis.MonoTouch.csproj create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Logging/ILogTestsBase.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Properties/AssemblyInfo.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/SerializationTestUtils.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/TraceEventArgs.cs diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3f7458e825eaa9b9961b0f54c1df1144c174bb31 GIT binary patch literal 6148 zcmeHK!AiqG5Z!I7Ca4e(LXS(&MbaG9f`W6l7)EdL zlzhJ(aP4)GiTb-({`d*xB8)Y}+~*4$?`IErM)5N%EU;lr6$Ed5ojk zt>#5k%<~|cY0q_3jKHILKg-6zhZH?XlVWt|G?z=S>$R2Vb;`C{cF)|lIz4yG(zY!7 zNVcrw*2%?HKYA*kUn(P`#MPo58d&wOE5?KsU17>a7DhT>=0$U|Jh+tR*l<5&DFcLGXY{lL}~3C6yS`q{F + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/.DS_Store b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7aa841e61ef691454ea60f0e00559aaf347b2067 GIT binary patch literal 6148 zcmeHK%}N6?5T0n&Eh_9q=yCB}N^1*x@UYYh9u$NYJXq0PSGo(eD|Sl{wYvBYK8J7P z^Y~2?i^X~s(V3Eblle(9A2itzk!p^j8j(vx4jQ9kWr47Hp=-$oD(SeJtx|pQU^GqYl_41@Gk79A#z{CyM8jvs?|5Ov|LzO zU2}>>XQO+T45D=0OhsgSEhRxt!drpHahDYn2H0?w0+UT<+ z%Hm76G?~Yg%VOCyFzcUZ znkd46Fdz&F1OJu*dr3I!|CRwMTo@1rzGHyT2M>+Wx0oB$M+Z9n1OOIb)&ia15}e~% z^eyHF;ejZV3N)$8J~5O@huyPrzQx?2NhhUO#yocAkH?GBtHbW;a8kZO>4gDdV4i_x zGj#d>Kg3^V;Uj-OMMlDaF!0A1P=!{z)kIPDZv9do-?bjv6&ef2<*Y!U&wT`7z~@Lw eJB{CC9dW+J+#t`wcAXBC4*^Yxbi%+7Fz^o44oEuy literal 0 HcmV?d00001 diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj new file mode 100644 index 0000000..bcbd71d --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj @@ -0,0 +1,117 @@ + + + + Debug + iPhoneSimulator + 10.0.0 + 2.0 + {04F451AA-0CEE-4971-AC7E-9D401114F1E2} + {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Exe + Common.Logging.MonoTouch.Tests + Resources + CommonLoggingMonoTouchTests + + + True + full + False + bin\iPhoneSimulator\Debug + DEBUG; + prompt + 4 + False + True + True + None + + + none + True + bin\iPhoneSimulator\Release + prompt + 4 + False + None + + + True + full + False + bin\iPhone\Debug + DEBUG; + prompt + 4 + False + iPhone Developer + True + True + + + none + True + bin\iPhone\Release + prompt + 4 + False + iPhone Developer + + + none + True + bin\iPhone\Ad-Hoc + prompt + 4 + True + False + Automatic:AdHoc + iPhone Distribution + + + none + True + bin\iPhone\AppStore + prompt + 4 + False + iPhone Distribution + Automatic:AppStore + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F} + Common.Logging.MonoTouch + + + {B928FD65-4E80-4F9D-96D0-830EDB3092DB} + Common.Logging.TestUtlis.MonoTouch + + + \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Info.plist b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Info.plist new file mode 100644 index 0000000..8653860 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Info.plist @@ -0,0 +1,26 @@ + + + + + UIDeviceFamily + + 1 + 2 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + MinimumOSVersion + 3.2 + + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTests.cs new file mode 100644 index 0000000..ddf2bdd --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTests.cs @@ -0,0 +1,98 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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 NUnit.Framework; + +namespace Common.Logging.Simple +{ + /// + /// Tests the class. + /// + /// Erich Eichinger + [TestFixture] + public class AbstractSimpleLoggerTests + { + private class ConcreteLogger : AbstractSimpleLogger + { + public ConcreteLogger(string logName, LogLevel logLevel, bool showlevel, bool showDateTime, bool showLogName, string dateTimeFormat) : base(logName, logLevel, showlevel, showDateTime, showLogName, dateTimeFormat) + {} + + protected override void WriteInternal(LogLevel level, object message, Exception exception) + { + throw new NotImplementedException(); + } + } + + private class ConcreteLoggerFactory : AbstractSimpleLoggerFactoryAdapter + { + public ConcreteLoggerFactory(NameValueCollection properties) : base(properties) + { + } + + protected override ILog CreateLogger(string name, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) + { + return new ConcreteLogger(name, level, showLevel, showDateTime, showLogName, dateTimeFormat); + } + } + + [Test] + public void IsSerializable() + { + Assert.IsTrue(SerializationTestUtils.IsSerializable()); + } + + [Test] + public void DefaultValues() + { + AbstractSimpleLogger logger; + logger = (AbstractSimpleLogger)new ConcreteLoggerFactory(null).GetLogger("x"); + Assert.AreEqual("x", logger.Name); + Assert.AreEqual(true, logger.ShowLogName); + Assert.AreEqual(true, logger.ShowDateTime); + Assert.AreEqual(true, logger.ShowLevel); + Assert.AreEqual(false, logger.HasDateTimeFormat); + Assert.AreEqual(string.Empty, logger.DateTimeFormat); + Assert.AreEqual(LogLevel.All, logger.CurrentLogLevel); + } + + [Test] + public void ConfiguredValues() + { + NameValueCollection props = new NameValueCollection(); + props["showLogName"] = "false"; + props["showLevel"] = "false"; + props["showDateTime"] = "false"; + props["dateTimeFormat"] = "MM"; + props["level"] = "Info"; + + AbstractSimpleLogger logger; + logger = (AbstractSimpleLogger)new ConcreteLoggerFactory(props).GetLogger("x"); + Assert.AreEqual("x", logger.Name); + Assert.AreEqual(false, logger.ShowLogName); + Assert.AreEqual(false, logger.ShowDateTime); + Assert.AreEqual(false, logger.ShowLevel); + Assert.AreEqual(true, logger.HasDateTimeFormat); + Assert.AreEqual("MM", logger.DateTimeFormat); + Assert.AreEqual(LogLevel.Info, logger.CurrentLogLevel); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTestsBase.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTestsBase.cs new file mode 100644 index 0000000..c6f4e30 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTestsBase.cs @@ -0,0 +1,46 @@ +#region License + +/* + * Copyright © 2002-2007 the original author or authors. + * + * 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.Collections.Specialized; + +namespace Common.Logging.Simple +{ + /// + /// Base class that exercises the basic api of the simple loggers. + /// To simplify testing derived classes you should derive your fixtures from this base fixture + /// + /// Mark Pollack + public abstract class AbstractSimpleLoggerTestsBase : ILogTestsBase + { + private static int count; + + protected static NameValueCollection CreateProperties() + { + NameValueCollection properties = new NameValueCollection(); + properties["showDateTime"] = "true"; + // if ((count % 2) == 0) + { + properties["dateTimeFormat"] = "yyyy/MM/dd HH:mm:ss:fff"; + } + count++; + return properties; + } + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/ConsoleOutLoggerTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/ConsoleOutLoggerTests.cs new file mode 100644 index 0000000..960e512 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/ConsoleOutLoggerTests.cs @@ -0,0 +1,56 @@ +#region License + +/* + * Copyright © 2002-2007 the original author or authors. + * + * 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 NUnit.Framework; + +namespace Common.Logging.Simple +{ + /// + /// Exercises the ConsoleOutLogger implementation. + /// + /// Mark Pollack + [TestFixture] + public class ConsoleOutLoggerTests : AbstractSimpleLoggerTestsBase + { + protected override ILoggerFactoryAdapter GetLoggerFactoryAdapter() + { + return new ConsoleOutLoggerFactoryAdapter(CreateProperties()); + } + + /// + /// Basic checks specific to ConsoleOutLogger + /// + [Test] + public void AssertDefaultSettings() + { + ILog log = LogManager.GetCurrentClassLogger(); + + Assert.IsNotNull(log); + Assert.AreEqual(typeof(ConsoleOutLogger),log.GetType()); + + // Can we call level checkers with no exceptions? + Assert.IsTrue(log.IsDebugEnabled); + Assert.IsTrue(log.IsInfoEnabled); + Assert.IsTrue(log.IsWarnEnabled); + Assert.IsTrue(log.IsErrorEnabled); + Assert.IsTrue(log.IsFatalEnabled); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Main.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Main.cs new file mode 100644 index 0000000..d8e37cf --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Main.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using MonoTouch.Foundation; +using MonoTouch.UIKit; + +namespace Common.Logging.MonoTouch.Tests +{ + public class Application + { + // This is the main entry point of the application. + static void Main (string[] args) + { + // if you want to use a different Application Delegate class from "UnitTestAppDelegate" + // you can specify it here. + UIApplication.Main (args, null, "UnitTestAppDelegate"); + } + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging new file mode 100644 index 0000000..6631ffa --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist new file mode 100644 index 0000000..5812f1e --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist @@ -0,0 +1,18 @@ + + + + + dateTimeFormat + + logLevel + LogLevel.Debug + logName + log4net for monotouch tests + showDateTime + true + showLevel + true + showLogName + true + + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Root.plist b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Root.plist new file mode 100644 index 0000000..943b963 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Root.plist @@ -0,0 +1,62 @@ + + + + + PreferenceSpecifiers + + + Type + PSGroupSpecifier + Title + Group + + + Type + PSTextFieldSpecifier + Title + Name + KeyboardType + Alphabet + AutocapitalizationType + None + AutocorrectionType + No + IsSecure + + Key + name_preference + DefaultValue + + + + Type + PSToggleSwitchSpecifier + Title + Enabled + Key + enabled_preference + DefaultValue + + + + Type + PSSliderSpecifier + MaximumValue + 1 + MaximumValueImage + + MinimumValue + 0 + MinimumValueImage + + Key + slider_preference + DefaultValue + 0.5 + + + StringsTable + Root + + + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/UnitTestAppDelegate.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/UnitTestAppDelegate.cs new file mode 100644 index 0000000..4dc25a7 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/UnitTestAppDelegate.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using MonoTouch.Foundation; +using MonoTouch.UIKit; +using MonoTouch.NUnit.UI; + +namespace Common.Logging.MonoTouch.Tests +{ + // The UIApplicationDelegate for the application. This class is responsible for launching the + // User Interface of the application, as well as listening (and optionally responding) to + // application events from iOS. + [Register ("UnitTestAppDelegate")] + public partial class UnitTestAppDelegate : UIApplicationDelegate + { + // class-level declarations + UIWindow window; + TouchRunner runner; + + // + // This method is invoked when the application has loaded and is ready to run. In this + // method you should instantiate the window, load the UI into it and then make the window + // visible. + // + // You have 17 seconds to return from this method, or iOS will terminate your application. + // + public override bool FinishedLaunching (UIApplication app, NSDictionary options) + { + // create a new window instance based on the screen size + window = new UIWindow (UIScreen.MainScreen.Bounds); + runner = new TouchRunner (window); + + // register every tests included in the main application/assembly + runner.Add (System.Reflection.Assembly.GetExecutingAssembly ()); + + window.RootViewController = new UINavigationController (runner.GetViewController ()); + + // make the window visible + window.MakeKeyAndVisible (); + + return true; + } + } +} + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln index b4b3f8d..c8eef57 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln @@ -3,12 +3,54 @@ Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.MonoTouch", "Common.Logging.MonoTouch\Common.Logging.MonoTouch.csproj", "{DD9F81C2-BA9A-4212-9249-2300C62AFF6F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.MonoTouch.Tests", "Common.Logging.MonoTouch.Tests\Common.Logging.MonoTouch.Tests.csproj", "{04F451AA-0CEE-4971-AC7E-9D401114F1E2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.TestUtlis.MonoTouch", "Common.Logging.TestUtlis.MonoTouch\Common.Logging.TestUtlis.MonoTouch.csproj", "{B928FD65-4E80-4F9D-96D0-830EDB3092DB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU + Debug|iPhoneSimulator = Debug|iPhoneSimulator + Release|iPhoneSimulator = Release|iPhoneSimulator + Debug|iPhone = Debug|iPhone + Release|iPhone = Release|iPhone + Ad-Hoc|iPhone = Ad-Hoc|iPhone + AppStore|iPhone = AppStore|iPhone EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Ad-Hoc|iPhone.ActiveCfg = Ad-Hoc|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Ad-Hoc|iPhone.Build.0 = Ad-Hoc|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.AppStore|iPhone.ActiveCfg = AppStore|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.AppStore|iPhone.Build.0 = AppStore|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Debug|iPhone.ActiveCfg = Debug|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Debug|iPhone.Build.0 = Debug|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Release|Any CPU.ActiveCfg = Release|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Release|Any CPU.Build.0 = Release|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Release|iPhone.ActiveCfg = Release|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Release|iPhone.Build.0 = Release|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.AppStore|iPhone.Build.0 = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Debug|iPhone.Build.0 = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|Any CPU.Build.0 = Release|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|iPhone.ActiveCfg = Release|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|iPhone.Build.0 = Release|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|iPhoneSimulator.Build.0 = Release|Any CPU {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Debug|Any CPU.Build.0 = Debug|Any CPU {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.userprefs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.userprefs new file mode 100644 index 0000000..6012b78 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.userprefs @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs index 3aed086..9af4ba1 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs @@ -18,6 +18,8 @@ #endregion using MonoTouch.Foundation; +using Common.Logging.Simple; +using System.Collections.Specialized; namespace Common.Logging.Configuration { @@ -40,9 +42,16 @@ public class MonoTouchConfigurationReader : IConfigurationReader ///

/// /// - public object GetSection(string sectionName) - { - return new NSDictionary (NSBundle.MainBundle.PathForResource (sectionName, null)); + public object GetSection (string sectionName) + { + NameValueCollection properties = new NameValueCollection(); + var nsDict = new NSDictionary (NSBundle.MainBundle.PathForResource (sectionName, null)); + foreach (var key in nsDict.Keys) + { + properties.Add(key.ToString(), nsDict[key].ToString()); + } + + return new LogSetting(typeof(ConsoleOutLoggerFactoryAdapter), properties); } } } \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs index f2a36f9..ae9aea1 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs @@ -20,6 +20,7 @@ using System.Collections.Specialized; using Common.Logging.Factory; +using Common.Logging.Configuration; namespace Common.Logging.Simple { @@ -136,6 +137,28 @@ public string DateTimeFormat set { _dateTimeFormat = value; } } + /// + /// Initializes a new instance of the class. + /// + /// + /// Looks for level, showDateTime, showLogName, dateTimeFormat items from + /// for use when the GetLogger methods are called. + /// for more information on how to use the + /// standard .NET application configuraiton file (App.config/Web.config) + /// to configure this adapter. + /// + /// The name value collection, typically specified by the user in + /// a configuration section named common/logging. + protected AbstractSimpleLoggerFactoryAdapter(NameValueCollection properties) + :this( + ArgUtils.TryParseEnum(LogLevel.All, ArgUtils.GetValue(properties, "level")), + ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showDateTime")), + ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showLogName")), + ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showLevel")), + ArgUtils.GetValue(properties, "dateTimeFormat", string.Empty) + ) + {} + /// /// Initializes a new instance of the class with /// default settings for the loggers created by this factory. diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs index 02b5455..1719a7d 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs @@ -23,59 +23,82 @@ namespace Common.Logging.Simple { - /// - /// Factory for creating instances that write data to . - /// - /// - /// - /// Below is an example how to configure this adapter: - /// - /// <configuration> - /// - /// <configSections> - /// <sectionGroup name="common"> - /// <section name="logging" - /// type="Common.Logging.ConfigurationSectionHandler, Common.Logging" - /// requirePermission="false" /> - /// </sectionGroup> - /// </configSections> - /// - /// <common> - /// <logging> - /// <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging"> - /// <arg key="level" value="ALL" /> - /// </factoryAdapter> - /// </logging> - /// </common> - /// - /// </configuration> - /// - /// - /// - /// - /// - /// - /// Gilles Bayon - /// Mark Pollack - /// Erich Eichinger - public class ConsoleOutLoggerFactoryAdapter : AbstractSimpleLoggerFactoryAdapter - { - - /// - /// Initializes a new instance of the class with - /// default settings for the loggers created by this factory. - /// - public ConsoleOutLoggerFactoryAdapter(LogLevel level, bool showDateTime, bool showLogName, bool showLevel, string dateTimeFormat) - : base(level, showDateTime, showLogName, showLevel, dateTimeFormat) - { } - - /// - /// Creates a new instance. - /// - protected override ILog CreateLogger(string name, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) - { - ILog log = new ConsoleOutLogger(name, level, showLevel, showDateTime, showLogName, dateTimeFormat); - return log; - } - } + /// + /// Factory for creating instances that write data to . + /// + /// + /// + /// Below is an example how to configure this adapter: + /// + /// <configuration> + /// + /// <configSections> + /// <sectionGroup name="common"> + /// <section name="logging" + /// type="Common.Logging.ConfigurationSectionHandler, Common.Logging" + /// requirePermission="false" /> + /// </sectionGroup> + /// </configSections> + /// + /// <common> + /// <logging> + /// <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging"> + /// <arg key="level" value="ALL" /> + /// </factoryAdapter> + /// </logging> + /// </common> + /// + /// </configuration> + /// + /// + /// + /// + /// + /// + /// Gilles Bayon + /// Mark Pollack + /// Erich Eichinger + public class ConsoleOutLoggerFactoryAdapter : AbstractSimpleLoggerFactoryAdapter + { + /// + /// Initializes a new instance of the class using default + /// settings. + /// + public ConsoleOutLoggerFactoryAdapter() + : base(null) + { } + + /// + /// Initializes a new instance of the class. + /// + /// + /// Looks for level, showDateTime, showLogName, dateTimeFormat items from + /// for use when the GetLogger methods are called. + /// for more information on how to use the + /// standard .NET application configuraiton file (App.config/Web.config) + /// to configure this adapter. + /// + /// The name value collection, typically specified by the user in + /// a configuration section named common/logging. + public ConsoleOutLoggerFactoryAdapter(NameValueCollection properties) + : base(properties) + { } + + /// + /// Initializes a new instance of the class with + /// default settings for the loggers created by this factory. + /// + public ConsoleOutLoggerFactoryAdapter(LogLevel level, bool showDateTime, bool showLogName, bool showLevel, string dateTimeFormat) + : base(level, showDateTime, showLogName, showLevel, dateTimeFormat) + { } + + /// + /// Creates a new instance. + /// + protected override ILog CreateLogger(string name, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) + { + ILog log = new ConsoleOutLogger(name, level, showLevel, showDateTime, showLogName, dateTimeFormat); + return log; + } + } } diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Common.Logging.TestUtlis.MonoTouch.csproj b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Common.Logging.TestUtlis.MonoTouch.csproj new file mode 100644 index 0000000..4bbee5d --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Common.Logging.TestUtlis.MonoTouch.csproj @@ -0,0 +1,55 @@ + + + + Debug + AnyCPU + 10.0.0 + 2.0 + {B928FD65-4E80-4F9D-96D0-830EDB3092DB} + {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Common.Logging.TestUtlis.MonoTouch + Resources + Common.Logging.TestUtlis.MonoTouch + + + True + full + False + bin\Debug + DEBUG; + prompt + 4 + False + + + none + True + bin\Release + prompt + 4 + False + + + + + + + + + + + + + + + + + + + + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F} + Common.Logging.MonoTouch + + + \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Logging/ILogTestsBase.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Logging/ILogTestsBase.cs new file mode 100644 index 0000000..ac155e1 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Logging/ILogTestsBase.cs @@ -0,0 +1,158 @@ +#region License + +/* + * Copyright © 2002-2006 the original author or authors. + * + * 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.Diagnostics; +using System.Reflection; +using System.Security; +using System.Security.Permissions; +using NUnit.Framework; +using Common.TestUtil; + +namespace Common.Logging +{ + /// + /// Generic tests that can be applied to any log implementation by + /// subclassing and defining the property LogObject. + /// + /// + /// Exercises basic API of the ILog implemetation. + /// + /// Mark Pollack + // [TestFixture] + public abstract class ILogTestsBase + { + [SetUp] + public virtual void SetUp() + { + //Security = new SecurityTemplate(true); + LogManager.Reset(); + LogManager.Adapter = GetLoggerFactoryAdapter(); + } + + protected abstract ILoggerFactoryAdapter GetLoggerFactoryAdapter(); + + [Test] + public void LoggingWithNullParameters() + { + Console.Out.WriteLine("Executing Test " + MethodBase.GetCurrentMethod().Name); + ILog log = LogManager.GetCurrentClassLogger(); + + log.Trace((object)null); + log.Trace((object)null, null); + log.Trace((Action)null); + log.Trace((Action)null, null); + log.Trace(null, (Action)null); + log.Trace(null, (Action)null, null); + log.TraceFormat((string)null); + log.TraceFormat(null, (Exception)null); + log.TraceFormat((IFormatProvider)null, null); + log.TraceFormat((IFormatProvider)null, null, (Exception)null); + + log.Debug((object)null); + log.Debug((object)null, null); + log.Debug((Action)null); + log.Debug((Action)null, null); + log.Debug(null, (Action)null); + log.Debug(null, (Action)null, null); + log.Debug(null); + log.Debug(null, (Exception)null); + log.Debug((IFormatProvider)null, null); + log.Debug((IFormatProvider)null, null, (Exception)null); + + } + + [Test] + public void CanCallIsEnabledFromNamedLog() + { + CanCallIsEnabled(LogManager.GetLogger("loggerName")); + } + + [Test] + public void CanLogMessageFromNamedLog() + { + CanLogMessage(LogManager.GetLogger("logger2Name")); + } + + [Test] + public void CanLogMessageWithExceptionFromNamedLog() + { + ILog log = LogManager.GetLogger("logger3Name"); + CanLogMessageWithException(log); + } + + [Test] + public void CanLogMessageWithExceptionFromTypeLog() + { + ILog log = LogManager.GetCurrentClassLogger(); + CanLogMessageWithException(log); + } + + protected virtual void CanCallIsEnabled(ILog log) + { + bool b; + b = log.IsTraceEnabled; + b = log.IsDebugEnabled; + b = log.IsInfoEnabled; + b = log.IsWarnEnabled; + b = log.IsErrorEnabled; + b = log.IsFatalEnabled; + } + + protected virtual void CanLogMessage(ILog log) + { + log.Trace("Hi Trace"); + log.Debug("Hi Debug"); + log.Info("Hi Info"); + log.Warn("Hi Warn"); + log.Error("Hi Error"); + log.Fatal("Hi Fatal"); + } + +#if NET_3_0 + protected virtual void CanLogMessageWithException(ILog log) + { + log.Trace(m => m("Hi {0}", "dude")); + log.Debug(m => m("Hi {0}", "dude"), new ArithmeticException()); + log.Info(m => m("Hi {0}", "dude"), new ArithmeticException()); + log.Warn(m => m("Hi {0}", "dude"), new ArithmeticException()); + log.Error(m => m("Hi {0}", "dude"), new ArithmeticException()); + log.Fatal(m => m("Hi {0}", "dude"), new ArithmeticException()); + } +#else + protected virtual void CanLogMessageWithException(ILog log) + { + log.TraceFormat("Hi {0}", new ArithmeticException(), "Trace"); + log.DebugFormat("Hi {0}", new ArithmeticException(), "Debug"); + log.InfoFormat("Hi {0}", new ArithmeticException(), "Info"); + log.WarnFormat("Hi {0}", new ArithmeticException(), "Warn"); + log.ErrorFormat("Hi {0}", new ArithmeticException(), "Error"); + log.FatalFormat("Hi {0}", new ArithmeticException(), "Fatal"); + } +#endif + + protected delegate TResult Func(TArg1 arg1); + + protected MethodBase GetMember(Func action) + { + return action.Method; + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Properties/AssemblyInfo.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3e71e62 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1ae77e17-60c0-473f-be37-657900f0f8e2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/SerializationTestUtils.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/SerializationTestUtils.cs new file mode 100644 index 0000000..7b645bb --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/SerializationTestUtils.cs @@ -0,0 +1,135 @@ +#region License + +/* + * Copyright 2002-2007 the original author or authors. + * + * 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.IO; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; +using NUnit.Framework; + +namespace Common.Logging +{ + /// + /// Utilities for testing serializability of objects. + /// + /// + /// Exposes static methods for use in other test cases. + /// + /// Erich Eichinger + [TestFixture] + public sealed class SerializationTestUtils + { + #region Test Ourselves + + [Test] + [ExpectedException(typeof(SerializationException))] + public void WithNonSerializableObject() + { + TestObject o = new TestObject(); + Assert.IsFalse(o is ISerializable); + Assert.IsFalse(IsSerializable(o)); + TrySerialization(o); + } + + [Test] + public void WithSerializableObject() + { + SerializableTestObject pA = new SerializableTestObject("propA"); + Assert.IsTrue(IsSerializable(pA)); + TrySerialization(pA); + SerializableTestObject pB = SerializeAndDeserialize(pA); + Assert.IsFalse(ReferenceEquals(pA, pB)); + Assert.AreEqual(pA.SomeProperty, pB.SomeProperty); + } + + #endregion + + /// + /// Attempts to serialize the specified object to an in-memory stream. + /// + /// the object to serialize + public static void TrySerialization(object o) + { + using (Stream stream = new MemoryStream()) + { + BinaryFormatter bformatter = new BinaryFormatter(); + bformatter.Serialize(stream, o); + } + } + + /// + /// Tests whether the specified object is serializable. + /// + /// the object to test. + /// true if the object is serializable, otherwise false. + public static bool IsSerializable(object o) + { + return o == null ? true : o.GetType().IsSerializable; + } + + /// + /// Tests whether instances of the specified type are serializable. + /// + /// true if the type is serializable, otherwise false. + public static bool IsSerializable() + { + return typeof(T).IsSerializable; + } + + /// + /// Serializes the specified object to an in-memory stream, and returns + /// the result of deserializing the object stream. + /// + /// the object to use. + /// the deserialized object. + public static T SerializeAndDeserialize(T o) + { + using (Stream stream = new MemoryStream()) + { + BinaryFormatter bformatter = new BinaryFormatter(); + bformatter.Serialize(stream, o); + stream.Flush(); + + stream.Seek(0, SeekOrigin.Begin); + T o2 = (T)bformatter.Deserialize(stream); + return o2; + } + } + + #region Test Classes + + private class TestObject + { + } + + [Serializable] + private class SerializableTestObject + { + public readonly string SomeProperty; + + public SerializableTestObject(string someProperty) + { + SomeProperty = someProperty; + } + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/TraceEventArgs.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/TraceEventArgs.cs new file mode 100644 index 0000000..a6ca827 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/TraceEventArgs.cs @@ -0,0 +1,54 @@ +using System; +using System.Diagnostics; +using System.Text; + +namespace Common.TestUtil +{ + public class TraceEventArgs + { + public string Source; + public string Category; + public int? Id; + public object[] Data; + public object Format; + public object[] Args; + public Guid? RelatedActivityId; + + public TraceEventArgs(string source, string category, int? id, object message, object[] args, object[] data, Guid? relatedActivityId) + { + Source = source; + Category = category; + Id = id; + Format = message; + Args = args; + Data = data; + RelatedActivityId = relatedActivityId; + } + + public string FormattedMessage + { + get + { + string msg = null; + if (Format == null && Data != null) + { + StringBuilder sb = new StringBuilder(); + foreach(object d in Data) + { + sb.Append(d); + } + msg = sb.ToString(); + } + else + { + msg = "" + Format; + } + if (Args != null) + { + return string.Format(msg, Args); + } + return msg; + } + } + } +} \ No newline at end of file diff --git a/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs b/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs index e033eb2..6a941c1 100644 --- a/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs +++ b/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs @@ -19,7 +19,7 @@ #endregion using System.Collections.Specialized; -using +using System.Configuration; namespace Common.Logging.Configuration { From 8e3309b02820d1745bee16748ae912d23121ed3f Mon Sep 17 00:00:00 2001 From: adamnation Date: Sun, 27 Jan 2013 12:32:11 -0800 Subject: [PATCH 04/12] fix issue with reading plist config, adding in more unit tests, removing use of Rhino.Mock --- .../Common.Logging.MonoTouch/.DS_Store | Bin 6148 -> 6148 bytes .../Common.Logging.MonoTouch.Tests.csproj | 5 +- .../Logging/Configuration/ArgUtilsTests.cs | 158 ++++++ .../MonoTouchConfigurationReaderTests.cs | 38 ++ .../Logging/Factory/AbstractLoggerTests.cs | 479 ++++++++++++++++++ .../Settings.bundle/Common.Logging.plist | 2 + .../MonoTouchConfigurationReader.cs | 2 +- 7 files changed, 682 insertions(+), 2 deletions(-) create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/ArgUtilsTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Factory/AbstractLoggerTests.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/.DS_Store b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/.DS_Store index 7aa841e61ef691454ea60f0e00559aaf347b2067..833f29edcb67c4b91dad89b81a8f7cb25fdc1353 100644 GIT binary patch delta 21 ccmZoMXffEZiIKy|%uGkY$joH(E=Dgg07$k5C;$Ke delta 21 ccmZoMXffEZiIKzD&`3wY#Kd^>E=Dgg07zE`9{>OV diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj index bcbd71d..20b5e63 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj @@ -91,7 +91,6 @@ - @@ -99,10 +98,14 @@ + + + + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/ArgUtilsTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/ArgUtilsTests.cs new file mode 100644 index 0000000..61a70d6 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/ArgUtilsTests.cs @@ -0,0 +1,158 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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.Runtime.Serialization; +using NUnit.Framework; + +namespace Common.Logging.Configuration +{ + /// + /// + /// Erich Eichinger + [TestFixture] + public class ArgUtilsTests + { + [Test] + public void GetValue() + { + NameValueCollection nvc = new NameValueCollection(); + nvc["key"] = "value"; + + Assert.AreEqual( null, ArgUtils.GetValue(null, "key")); + Assert.AreEqual("value", ArgUtils.GetValue(nvc, "key")); + Assert.AreEqual(null, ArgUtils.GetValue(nvc, "wrongkey")); + Assert.AreEqual("defaultValue", ArgUtils.GetValue(null, "wrongkey", "defaultValue")); + Assert.AreEqual("defaultValue", ArgUtils.GetValue(nvc, "wrongkey", "defaultValue")); + } + + [Test] + public void Coalesce() + { + Assert.AreEqual(null, ArgUtils.Coalesce()); + Assert.AreEqual(null, ArgUtils.Coalesce(null, null)); + Assert.AreEqual("x", ArgUtils.Coalesce(string.Empty, null, "x")); + // null predicate causes the use the default predicate of (v!=null) + Assert.AreEqual(string.Empty, ArgUtils.Coalesce( (Predicate)null, string.Empty, (string)null, "x")); + Assert.AreEqual(null, ArgUtils.Coalesce( delegate(object v) { return v != null; } )); + Assert.AreEqual(string.Empty, ArgUtils.Coalesce( delegate(object v) { return v != null; }, null, string.Empty, "x")); + } + + [Test] + public void TryParseEnum() + { + Assert.Throws( + Is.TypeOf().And.Message.EqualTo( string.Format("Type '{0}' is not an enum type", typeof(int).FullName) ) + , delegate + { + ArgUtils.TryParseEnum((int) 1, "0"); + } + ); + + Assert.AreEqual( LogLevel.Fatal, ArgUtils.TryParseEnum(LogLevel.All, "fatal") ); + Assert.AreEqual( LogLevel.Debug, ArgUtils.TryParseEnum(LogLevel.Debug, "invalid value") ); + Assert.AreEqual( LogLevel.Debug, ArgUtils.TryParseEnum(LogLevel.Debug, null) ); + } + + [Test] + public void TryParse() + { + Assert.Throws( + Is.TypeOf() + .And.Message.EqualTo(string.Format("There is no parser registered for type {0}", typeof(object).FullName)) + , delegate + { + ArgUtils.TryParse(new object(), "0"); + } + ); + + Assert.AreEqual( true, ArgUtils.TryParse(false, "trUE") ); + Assert.AreEqual( 1, ArgUtils.TryParse(2, "1") ); + Assert.AreEqual( 2, ArgUtils.TryParse(2, "2invalidnumber1") ); + Assert.AreEqual( (short)1, ArgUtils.TryParse((short)2, "1") ); + Assert.AreEqual( (long)1, ArgUtils.TryParse((long)2, "1") ); + Assert.AreEqual( (float)1, ArgUtils.TryParse((float)2, "1") ); + Assert.AreEqual( (double)1, ArgUtils.TryParse((double)2, "1") ); + Assert.AreEqual( (decimal)1, ArgUtils.TryParse((decimal)2, "1") ); + } + + [Test] + public void AssertIsAssignable() + { + Assert.Throws( + Is.TypeOf() + .And.Message.EqualTo(new ArgumentNullException("valType").Message) + , delegate + { + ArgUtils.AssertIsAssignable("arg", null); + } + ); + + Assert.Throws( + Is.TypeOf() + .And.Message.EqualTo(new ArgumentOutOfRangeException("this", this.GetType(),string.Format("Type '{0}' of parameter '{1}' is not assignable to target type '{2}'" + , this.GetType().AssemblyQualifiedName + , "this" + , typeof (ISerializable).AssemblyQualifiedName) ).Message) + , delegate + { + ArgUtils.AssertIsAssignable("this", this.GetType()); + } + ); + + Type type = typeof(Int32); + Assert.AreSame(type, ArgUtils.AssertIsAssignable("arg", type)); + } + + [Test] + public void AssertNotNullThrowsArgumentNullException() + { + object tmp = new object(); + Assert.AreSame(tmp, ArgUtils.AssertNotNull("arg", tmp)); + Assert.Throws(Is.TypeOf() + .And.Message.EqualTo(new ArgumentNullException("tmp").Message), + delegate { ArgUtils.AssertNotNull("tmp", (object)null); }); + Assert.Throws(Is.TypeOf().And.Message.EqualTo(new ArgumentNullException("tmp", "message msgarg").Message), + delegate { ArgUtils.AssertNotNull("tmp", (object)null, "message {0}", "msgarg"); }); + } + + [Test] + public void Guard() + { + ArgUtils.Guard(delegate { }, "format {0}", "fmtarg"); + Assert.AreEqual(1, ArgUtils.Guard(delegate { return 1; }, "format {0}", "fmtarg")); + + Assert.Throws(Is.TypeOf() + .And.Message.EqualTo("innermessage"), + delegate + { + ArgUtils.Guard(delegate { throw new ConfigurationException("innermessage"); }, "format {0}", "fmtarg"); + }); + + Assert.Throws(Is.TypeOf() + .And.Message.EqualTo("format fmtarg"), + delegate + { + ArgUtils.Guard(delegate { throw new ArgumentException("innermessage"); }, "format {0}", "fmtarg"); + }); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs new file mode 100644 index 0000000..d4e9c5d --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs @@ -0,0 +1,38 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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.Collections.Specialized; +using NUnit.Framework; + +namespace Common.Logging.Configuration +{ + /// + /// + /// Erich Eichinger + [TestFixture] + public class MonoTouchConfigurationReaderTests + { + [Test] + public void ReadsAppConfig() + { + Assert.AreEqual("FromAppConfig", ((NameValueCollection)new MonoTouchConfigurationReader().GetSection("Settings.bundle/Common.Logging.plist"))["appConfigCheck"]); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Factory/AbstractLoggerTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Factory/AbstractLoggerTests.cs new file mode 100644 index 0000000..1f19f42 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Factory/AbstractLoggerTests.cs @@ -0,0 +1,479 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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.Globalization; +using System.Reflection; +using NUnit.Framework; +//using Rhino.Mocks; +//using Rhino.Mocks.Interfaces; +using FormatMessageCallback = System.Action; +//using Is=Rhino.Mocks.Constraints.Is; + +namespace Common.Logging.Factory +{ + /// + /// Tests for class. In particular ensures, that all ILog.XXX methods + /// correctuly route to the single WriteInternal delegate. + /// + [TestFixture] + public class AbstractLoggerTests + { + [Test] + public void IsSerializable() + { + SerializationTestUtils.IsSerializable(); + } + + [Test] + public void ImplementsAllMethodsForAllLevels() + { + string[] logLevels = Exclude(Enum.GetNames(typeof (LogLevel)), "All", "Off"); + + foreach (string logLevel in logLevels) + { + MethodInfo[] logMethods = GetLogMethodSignatures(logLevel); + for (int i = 0; i < logLevels.Length; i++) + { + Assert.IsNotNull(logMethods[i], + "Method with signature #{0} not implemented for level {1}", i, logLevel); + } + } + } + + [Test] + public void LogsMessage() + { + string[] logLevels = Exclude(Enum.GetNames(typeof(LogLevel)), "All", "Off"); + + foreach (string logLevel in logLevels) + { + LogsMessage(logLevel); + } + } + + /// + /// Ensures, that all interface methods delegate to Write() with correct level + arguments + /// and that arguments are still not evaluated up to this point (e.g. calling ToString()) + /// + private static void LogsMessage(string levelName) + { + //MockRepository mocks = new MockRepository(); + + TestLogger log = new TestLogger(); + Exception ex = new Exception(); + + + MethodInfo[] logMethods = GetLogMethodSignatures(levelName); + + LogLevel logLevel = (LogLevel)Enum.Parse(typeof(LogLevel), levelName); + + Invoke(log, logMethods[0], "messageObject0"); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("messageObject0", log.LastMessage); + Assert.AreEqual(null, log.LastException); + + Invoke(log, logMethods[1], "messageObject1", ex); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("messageObject1", log.LastMessage); + Assert.AreEqual(ex, log.LastException); + + Invoke(log, logMethods[2], "format2 {0}", new object[] { "arg2" }); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("format2 arg2", log.LastMessage); + Assert.AreEqual(null, log.LastException); + + Invoke(log, logMethods[3], "format3 {0}", ex, new object[] { "arg3" }); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("format3 arg3", log.LastMessage); + Assert.AreEqual(ex, log.LastException); + + Invoke(log, logMethods[4], CultureInfo.CreateSpecificCulture("de-de"), "format4 {0}", new object[] { 4.1 }); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("format4 4,1", log.LastMessage); + Assert.AreEqual(null, log.LastException); + + Invoke(log, logMethods[5], CultureInfo.CreateSpecificCulture("de-de"), "format5 {0}", ex, new object[] { 5.1 }); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("format5 5,1", log.LastMessage); + Assert.AreEqual(ex, log.LastException); + + Invoke(log, logMethods[6], TestFormatMessageCallback.MessageCallback("message6")); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("message6", log.LastMessage); + Assert.AreEqual(null, log.LastException); + + Invoke(log, logMethods[7], TestFormatMessageCallback.MessageCallback("message7"), ex); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("message7", log.LastMessage); + Assert.AreEqual(ex, log.LastException); + + Invoke(log, logMethods[8], CultureInfo.CreateSpecificCulture("de-de"), TestFormatMessageCallback.MessageCallback("format8 {0}", new object[] { 8.1 })); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("format8 8,1", log.LastMessage); + Assert.AreEqual(null, log.LastException); + + Invoke(log, logMethods[9], CultureInfo.CreateSpecificCulture("de-de"), TestFormatMessageCallback.MessageCallback("format9 {0}", new object[] { 9.1 }), ex); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("format9 9,1", log.LastMessage); + Assert.AreEqual(ex, log.LastException); + } + /* + [Test] + public void WriteIsCalledWithCorrectLogLevel() + { + string[] logLevels = Exclude(Enum.GetNames(typeof(LogLevel)), "All", "Off"); + + foreach (string logLevel in logLevels) + { + WriteIsCalledWithCorrectLogLevel(logLevel); + } + } + + /// + /// Ensures, that all interface methods delegate to Write() with correct level + arguments + /// and that arguments are still not evaluated up to this point (e.g. calling ToString()) + /// + private static void WriteIsCalledWithCorrectLogLevel(string levelName) + { + MockRepository mocks = new MockRepository(); + + AbstractTestLogger log = (AbstractTestLogger)mocks.PartialMock(typeof(AbstractTestLogger)); + Exception ex = (Exception)mocks.StrictMock(typeof(Exception)); + object messageObject = mocks.StrictMock(typeof(object)); + object formatArg = mocks.StrictMock(typeof(object)); + FormatMessageCallback failCallback = TestFormatMessageCallback.FailCallback(); + + MethodInfo[] logMethods = GetLogMethodSignatures(levelName); + + LogLevel logLevel = (LogLevel) Enum.Parse(typeof (LogLevel), levelName); + + using (mocks.Ordered()) + { + log.Log(logLevel, null, null); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); + log.Log(logLevel, null, ex); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); + log.Log(logLevel, null, null); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); + log.Log(logLevel, null, ex); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); + log.Log(logLevel, null, null); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); + log.Log(logLevel, null, ex); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); + log.Log(logLevel, null, null); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); + log.Log(logLevel, null, ex); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); + log.Log(logLevel, null, null); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); + log.Log(logLevel, null, ex); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); + } + mocks.ReplayAll(); + + Invoke(log, logMethods[0], messageObject); + Invoke(log, logMethods[1], messageObject, ex); + Invoke(log, logMethods[2], "format", new object[] { formatArg }); + Invoke(log, logMethods[3], "format", ex, new object[] { formatArg }); + Invoke(log, logMethods[4], CultureInfo.InvariantCulture, "format", new object[] { formatArg }); + Invoke(log, logMethods[5], CultureInfo.InvariantCulture, "format", ex, new object[] { formatArg }); + Invoke(log, logMethods[6], failCallback); + Invoke(log, logMethods[7], failCallback, ex); + Invoke(log, logMethods[8], CultureInfo.InvariantCulture, failCallback); + Invoke(log, logMethods[9], CultureInfo.InvariantCulture, failCallback, ex); + + mocks.VerifyAll(); + } +*/ + /* + [Test] + public void WriteAndEvaluateOnlyWhenLevelEnabled() + { + string[] logLevels = Exclude(Enum.GetNames(typeof(LogLevel)), "All", "Off"); + + foreach (string logLevel in logLevels) + { + WriteAndEvaluateOnlyWhenLevelEnabled(logLevel); + } + } + + /// + /// This test ensures, that for a given loglevel + /// a) AbstractLogger.Write is not called if that loglevel is disabled + /// b) No argument is evaluated (e.g. calling ToString()) if that loglevel is disabled + /// + private static void WriteAndEvaluateOnlyWhenLevelEnabled(string levelName) + { + MockRepository mocks = new MockRepository(); + + AbstractLogger log = (AbstractLogger)mocks.StrictMock(typeof(AbstractLogger)); + Exception ex = (Exception)mocks.StrictMock(typeof(Exception)); + object messageObject = mocks.StrictMock(typeof(object)); + object formatArg = mocks.StrictMock(typeof(object)); + FormatMessageCallback failCallback = TestFormatMessageCallback.FailCallback(); + + MethodInfo[] logMethods = GetLogMethodSignatures(levelName); + + using (mocks.Ordered()) + { + Invoke(log, logMethods[0], messageObject); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[1], messageObject, ex); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[2], "format", new object[] { formatArg }); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[3], "format", ex, new object[] { formatArg }); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[4], CultureInfo.InvariantCulture, "format", new object[] { formatArg }); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[5], CultureInfo.InvariantCulture, "format", ex, new object[] { formatArg }); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[6], failCallback); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[7], failCallback, ex); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[8], CultureInfo.InvariantCulture, failCallback); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[9], CultureInfo.InvariantCulture, failCallback, ex); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + } + mocks.ReplayAll(); + + Invoke(log, logMethods[0], messageObject); + Invoke(log, logMethods[1], messageObject, ex); + Invoke(log, logMethods[2], "format", new object[] {formatArg}); + Invoke(log, logMethods[3], "format", ex, new object[] { formatArg }); + Invoke(log, logMethods[4], CultureInfo.InvariantCulture, "format", new object[] {formatArg}); + Invoke(log, logMethods[5], CultureInfo.InvariantCulture, "format", ex, new object[] { formatArg }); + Invoke(log, logMethods[6], failCallback); + Invoke(log, logMethods[7], failCallback, ex); + Invoke(log, logMethods[8], CultureInfo.InvariantCulture, failCallback); + Invoke(log, logMethods[9], CultureInfo.InvariantCulture, failCallback, ex); + + mocks.VerifyAll(); + } +*/ + private static bool IsLevelEnabled(ILog log, string logLevelName) + { + switch(logLevelName) + { + case "Trace": + return log.IsTraceEnabled; + case "Debug": + return log.IsDebugEnabled; + case "Info": + return log.IsInfoEnabled; + case "Warn": + return log.IsWarnEnabled; + case "Error": + return log.IsErrorEnabled; + case "Fatal": + return log.IsFatalEnabled; + default: + throw new ArgumentOutOfRangeException("logLevelName", logLevelName, "unknown log level "); + } + } + + private static readonly Type[][] methodSignatures = + { + new Type[] {typeof (object)}, + new Type[] {typeof (object), typeof (Exception)}, + new Type[] {typeof (string), typeof (object[])}, + new Type[] {typeof (string), typeof (Exception), typeof (object[])}, + new Type[] {typeof (IFormatProvider), typeof (string), typeof (object[])}, + new Type[] {typeof (IFormatProvider), typeof (string), typeof (Exception), typeof (object[])}, + new Type[] {typeof (FormatMessageCallback)}, + new Type[] {typeof (FormatMessageCallback), typeof (Exception)}, + new Type[] {typeof (IFormatProvider), typeof (FormatMessageCallback)}, + new Type[] {typeof (IFormatProvider), typeof (FormatMessageCallback), typeof (Exception)} + }; + + private static MethodInfo[] GetLogMethodSignatures(string levelName) + { + return new MethodInfo[] + { + typeof (ILog).GetMethod(levelName, methodSignatures[0]), + typeof (ILog).GetMethod(levelName, methodSignatures[1]), + typeof (ILog).GetMethod(levelName + "Format", methodSignatures[2]), + typeof (ILog).GetMethod(levelName + "Format", methodSignatures[3]), + typeof (ILog).GetMethod(levelName + "Format", methodSignatures[4]), + typeof (ILog).GetMethod(levelName + "Format", methodSignatures[5]), + typeof (ILog).GetMethod(levelName, methodSignatures[6]), + typeof (ILog).GetMethod(levelName, methodSignatures[7]), + typeof (ILog).GetMethod(levelName, methodSignatures[8]), + typeof (ILog).GetMethod(levelName, methodSignatures[9]) + }; + } + + private static void Invoke(object target, MethodInfo method, params object[] args) + { + method.Invoke(target, args); + } + + #region TestFormatMessageCallback Utility Class + + private class TestFormatMessageCallback + { + private readonly bool throwOnInvocation; + private readonly string messageToReturn; + private readonly object[] argsToReturn; + + private TestFormatMessageCallback(bool throwOnInvocation) + { + this.throwOnInvocation = throwOnInvocation; + } + + private TestFormatMessageCallback(string messageToReturn, object[] args) + { + this.messageToReturn = messageToReturn; + this.argsToReturn = args; + } + + public static FormatMessageCallback FailCallback() + { + return new FormatMessageCallback(new TestFormatMessageCallback(true).FormatMessage); + } + + public static FormatMessageCallback MessageCallback(string message, params object[] args) + { + return new FormatMessageCallback(new TestFormatMessageCallback(message, args).FormatMessage); + } + + private void FormatMessage(FormatMessageHandler fmh) + { + if (throwOnInvocation) + { + Assert.Fail(); + } + fmh(messageToReturn, argsToReturn); + } + } + + #endregion + + private static string[] Exclude(string[] arr, params string[] exclude) + { + ArrayList result = new ArrayList(); + foreach (string s in arr) + { + if (0 > Array.BinarySearch(exclude, s)) + { + result.Add(s); + } + } + return (string[]) result.ToArray(typeof (string)); + } + + public class TestLogger : AbstractTestLogger + { + public LogLevel LastLogLevel; + public string LastMessage; + public Exception LastException; + + protected override WriteHandler GetWriteHandler() + { + return new WriteHandler(Log); + } + + protected override void WriteInternal(LogLevel level, object message, Exception exception) + { + Assert.Fail("must never been called - Log() should be called"); + } + + public override void Log(LogLevel level, object message, Exception exception) + { + LastLogLevel = level; + LastMessage = message.ToString(); + LastException = exception; + } + } + + public abstract class AbstractTestLogger : AbstractLogger + { + protected override void WriteInternal(LogLevel level, object message, Exception exception) + { + Log(level, message, exception); + } + + public abstract void Log(LogLevel level, object message, Exception exception); + + /// + /// Checks if this logger is enabled for the level. + /// + public override bool IsTraceEnabled + { + get { return true; } + } + + /// + /// Checks if this logger is enabled for the level. + /// + public override bool IsDebugEnabled + { + get { return true; } + } + + /// + /// Checks if this logger is enabled for the level. + /// + public override bool IsErrorEnabled + { + get { return true; } + } + + /// + /// Checks if this logger is enabled for the level. + /// + public override bool IsFatalEnabled + { + get { return true; } + } + + /// + /// Checks if this logger is enabled for the level. + /// + public override bool IsInfoEnabled + { + get { return true; } + } + + /// + /// Checks if this logger is enabled for the level. + /// + public override bool IsWarnEnabled + { + get { return true; } + } + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist index 5812f1e..5443b06 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist @@ -2,6 +2,8 @@ + appConfigCheck + FromAppConfig dateTimeFormat logLevel diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs index 9af4ba1..4d4175e 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs @@ -51,7 +51,7 @@ public object GetSection (string sectionName) properties.Add(key.ToString(), nsDict[key].ToString()); } - return new LogSetting(typeof(ConsoleOutLoggerFactoryAdapter), properties); + return properties; } } } \ No newline at end of file From 29deb04bbe86ac49496759489491f1fe5a65054e Mon Sep 17 00:00:00 2001 From: adamnation Date: Sun, 27 Jan 2013 14:02:19 -0800 Subject: [PATCH 05/12] adding more tests, fixed a bug in config reader --- .../AssemblyInfo.cs | 29 ++ .../Common.Logging.MonoTouch.Tests.csproj | 8 + .../ExceptionsTest.cs | 450 ++++++++++++++++++ .../MonoTouchConfigurationReaderTests.cs | 4 +- .../Logging/LogManagerTests.cs | 63 +++ .../Logging/LoggingExceptionTests.cs | 42 ++ .../Logging/MissingCtorFactoryAdapter.cs | 49 ++ .../MethodInvokePerformanceTests.cs | 62 +++ .../Settings.bundle/Common.Logging.plist | 6 +- .../StandardsComplianceTest.cs | 109 +++++ .../StopWatch.cs | 99 ++++ .../MonoTouchConfigurationReader.cs | 2 +- 12 files changed, 916 insertions(+), 7 deletions(-) create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/AssemblyInfo.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/ExceptionsTest.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LogManagerTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LoggingExceptionTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/MissingCtorFactoryAdapter.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/MethodInvokePerformanceTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StandardsComplianceTest.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StopWatch.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/AssemblyInfo.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/AssemblyInfo.cs new file mode 100644 index 0000000..1c11957 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/AssemblyInfo.cs @@ -0,0 +1,29 @@ +using System.Reflection; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly: AssemblyVersion("1.0.*")] + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj index 20b5e63..7e79e5b 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj @@ -101,6 +101,14 @@ + + + + + + + + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/ExceptionsTest.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/ExceptionsTest.cs new file mode 100644 index 0000000..f4affbc --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/ExceptionsTest.cs @@ -0,0 +1,450 @@ +#region License + +/* + * Copyright © 2002-2007 the original author or authors. + * + * 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 + +#region Imports + +using System; +using System.Globalization; +using System.IO; +using System.Reflection; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; +using NUnit.Framework; + +#endregion + +namespace Common +{ + /// + /// Tests the various exception classes. + /// + /// + /// + /// Shamelessly lifted from the NAnt test suite. + /// + /// + /// Rick Evans + /// $Id:$ + public abstract class ExceptionsTest : StandardsComplianceTest + { + protected ExceptionsTest() + { + CheckedType = typeof (Exception); + } + + #region Tests + + [Test] + public void TestStandardsCompliance() + { + ProcessAssembly(AssemblyToCheck); + } + + [Test] + public void TestThisTest() + { + ProcessAssembly(Assembly.GetAssembly(GetType())); + } + + #endregion + + #region Methods + + protected override void CheckStandardsCompliance(Assembly assembly, Type t) + { + // check to see that the exception is correctly named, with "Exception" at the end + bool nameIsValid = t.Name.EndsWith("Exception"); + Assert.IsTrue(nameIsValid, t.Name + " class name must end with Exception."); + if (t.IsAbstract) + { + return; + } + // Does the exception have the 3 standard constructors? + // Default constructor + CheckPublicConstructor(t, "()"); + // Constructor with a single string parameter + CheckPublicConstructor(t, "(string message)", typeof (String)); + // Constructor with a string and an inner exception + CheckPublicConstructor(t, "(string message, Exception inner)", + typeof (String), typeof (Exception)); + // check to see if the serialization constructor is present + // if exception is sealed, constructor should be private + // if exception is not sealed, constructor should be protected + if (t.IsSealed) + { + // check to see if the private serialization constructor is present... + CheckPrivateConstructor(t, "(SerializationInfo info, StreamingContext context)", + typeof (SerializationInfo), + typeof (StreamingContext)); + } + else + { + // check to see if the protected serialization constructor is present... + CheckProtectedConstructor(t, "(SerializationInfo info, StreamingContext context)", + typeof (SerializationInfo), + typeof (StreamingContext)); + } + // check to see if the type is marked as serializable + Assert.IsTrue(t.IsSerializable, t.Name + " is not serializable, missing [Serializable]?"); + // check to see if there are any public fields. These should be properties instead... + FieldInfo[] publicFields = + t.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); + if (publicFields.Length != 0) + { + foreach (FieldInfo fieldInfo in publicFields) + { + Assert.Fail(t.Name + "." + fieldInfo.Name + + " is a public field, should be exposed through property instead."); + } + } + // If this exception has any fields, check to make sure it has a + // version of GetObjectData. If not, it does't serialize those fields. + FieldInfo[] fields = + t.GetFields(BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public | + BindingFlags.Instance); + if (fields.Length != 0) + { + if ( + t.GetMethod("GetObjectData", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance) == + null) + { + Assert.Fail(t.Name + " does not implement GetObjectData but has private fields."); + } + } + if (!t.IsAbstract) + { + CheckInstantiation(t); + } + } + + /// + /// Checks the public constructor. + /// + /// The type + /// The description. + /// The parameters. + private void CheckPublicConstructor(Type t, string description, params Type[] parameters) + { + // locate constructor + ConstructorInfo ci = + t.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, parameters, + null); + // fail if constructor does not exist + Assert.IsNotNull(ci, t.Name + description + " is a required constructor."); + // fail if constructor is private + Assert.IsFalse(ci.IsPrivate, t.Name + description + " is private, must be public."); + // fail if constructor is protected + Assert.IsFalse(ci.IsFamily, t.Name + description + " is internal, must be public."); + // fail if constructor is internal + Assert.IsFalse(ci.IsAssembly, t.Name + description + " is internal, must be public."); + // fail if constructor is protected internal + Assert.IsFalse(ci.IsFamilyOrAssembly, t.Name + description + " is protected internal, must be public."); + // sanity check to make sure the constructor is public + Assert.IsTrue(ci.IsPublic, t.Name + description + " is not public, must be public."); + } + + private void CheckProtectedConstructor(Type t, string description, params Type[] parameters) + { + // locate constructor + ConstructorInfo ci = + t.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, parameters, + null); + // fail if constructor does not exist + Assert.IsNotNull(ci, t.Name + description + " is a required constructor."); + // fail if constructor is public + Assert.IsFalse(ci.IsPublic, t.Name + description + " is public, must be protected."); + // fail if constructor is private + Assert.IsFalse(ci.IsPrivate, t.Name + description + " is private, must be public or protected."); + // fail if constructor is internal + Assert.IsFalse(ci.IsAssembly, t.Name + description + " is internal, must be protected."); + // fail if constructor is protected internal + Assert.IsFalse(ci.IsFamilyOrAssembly, t.Name + description + " is protected internal, must be protected."); + // sanity check to make sure the constructor is protected + Assert.IsTrue(ci.IsFamily, t.Name + description + " is not protected, must be protected."); + } + + private void CheckPrivateConstructor(Type t, string description, params Type[] parameters) + { + // locate constructor + ConstructorInfo ci = + t.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, parameters, + null); + // fail if constructor does not exist + Assert.IsNotNull(ci, t.Name + description + " is a required constructor."); + // fail if constructor is public + Assert.IsFalse(ci.IsPublic, t.Name + description + " is public, must be private."); + // fail if constructor is protected + Assert.IsFalse(ci.IsFamily, t.Name + description + " is protected, must be private."); + // fail if constructor is internal + Assert.IsFalse(ci.IsAssembly, t.Name + description + " is internal, must be private."); + // fail if constructor is protected internal + Assert.IsFalse(ci.IsFamilyOrAssembly, t.Name + description + " is protected internal, must be private."); + // sanity check to make sure the constructor is private + Assert.IsTrue(ci.IsPrivate, t.Name + description + " is not private, must be private."); + } + + /// + /// If we've got here, then the standards compliance tests have passed... + /// + /// The exception type being tested. + private void CheckInstantiation(Type t) + { + // attempt to instantiate the 3 standard ctors... + ConstructorInfo ctor = t.GetConstructor(Type.EmptyTypes); + try + { + ctor.Invoke(null); + } + catch (Exception ex) + { + Assert.Fail("Ctor () for '" + t.Name + "' threw an exception : " + ex.Message); + } + ctor = t.GetConstructor(new Type[] {typeof (string)}); + try + { + Exception ex = (Exception) ctor.Invoke(new object[] {"My Fingers Turn To Fists"}); + Assert.IsNotNull(ex.Message, t.Name + "'s Message was null."); + } + catch (Exception ex) + { + Assert.Fail("Ctor (string) for '" + t.Name + "' threw an exception : " + ex.Message); + } + ctor = t.GetConstructor(new Type[] {typeof (string), typeof (Exception)}); + try + { + Exception ex = + (Exception) ctor.Invoke(new object[] {"My Fingers Turn To Fists", new FormatException("Bing")}); + Assert.IsNotNull(ex.Message, t.Name + "'s Message was null."); + Assert.IsNotNull(ex.InnerException, t.Name + "'s InnerException was null."); + Assert.AreEqual("Bing", ex.InnerException.Message); + } + catch (Exception ex) + { + Assert.Fail("Ctor (string, Exception) for '" + t.Name + "' threw an exception : " + ex.Message); + } + // test the serialization ctor + try + { + ctor = t.GetConstructor(new Type[] {typeof (string)}); + Exception ex = (Exception) ctor.Invoke(new object[] {"HungerHurtsButStarvingWorks"}); + BinaryFormatter bf = new BinaryFormatter(); + MemoryStream ms = new MemoryStream(); + bf.Serialize(ms, ex); + ms.Seek(0, 0); + Exception inex = (Exception) bf.Deserialize(ms); + Assert.IsNotNull(inex); + } + catch (Exception ex) + { + Assert.Fail("Ctor (Serialization) for '" + t.Name + "' threw an exception : " + ex.Message); + } + } + + #endregion + + #region Properties + + /// + /// We will test all of the exceptions in this assembly for their correctness. + /// + protected Assembly AssemblyToCheck + { + get { return _assemblyToCheck; } + set { _assemblyToCheck = value; } + } + + #endregion + + private Assembly _assemblyToCheck = null; + } + + #region Inner Class : SimpleTestException + + /// + /// Do nothing exception to verify that the exception tester + /// is working correctly. + /// + [Serializable] + public class SimpleTestException : ApplicationException + { + #region Public Instance Constructors + + public SimpleTestException() + { + } + + public SimpleTestException(string message) : base(message) + { + } + + public SimpleTestException(string message, Exception inner) + : base(message, inner) + { + } + + #endregion Public Instance Constructors + + #region Protected Instance Constructors + + // deserialization constructor + protected SimpleTestException( + SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + + #endregion Protected Instance Constructors + } + + #endregion + + #region Inner Class : TestException + + /// + /// Exception to verify that the exception tester is working correctly. + /// + [Serializable] + public class TestException : ApplicationException, ISerializable + { + #region Private Instance Fields + + private int _value; + + #endregion Private Instance Fields + + #region Public Instance Constructors + + public TestException() + { + } + + public TestException(string message) : base(message) + { + } + + public TestException(string message, Exception inner) + : base(message, inner) + { + } + + // constructors that take the added value + public TestException(string message, int value) : base(message) + { + _value = value; + } + + #endregion Public Instance Constructors + + #region Protected Instance Constructors + + // deserialization constructor + protected TestException(SerializationInfo info, StreamingContext context) : base(info, context) + { + _value = info.GetInt32("Value"); + } + + #endregion Protected Instance Constructors + + #region Public Instance Properties + + public int Value + { + get { return _value; } + } + + #endregion Public Instance Properties + + #region Override implementation of ApplicationException + + // Called by the frameworks during serialization + // to fetch the data from an object. + public override void GetObjectData( + SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + info.AddValue("Value", _value); + } + + // overridden Message property. This will give the + // proper textual representation of the exception, + // with the added field value. + public override string Message + { + get + { + // NOTE: should be localized... + string s = + string.Format( + CultureInfo.InvariantCulture, "Value: {0}", _value); + return base.Message + Environment.NewLine + s; + } + } + + #endregion Override implementation of ApplicationException + } + + #endregion + + #region Inner Class : SealedTestException + + /// + /// Exception to verify that the exception tester is working on + /// sealed exception. + /// + [Serializable] + public sealed class SealedTestException : TestException + { + #region Public Instance Constructors + + public SealedTestException() + { + } + + public SealedTestException(string message) : base(message) + { + } + + public SealedTestException(string message, Exception inner) + : base(message, inner) + { + } + + // constructors that take the added value + public SealedTestException(string message, int value) + : base(message, value) + { + } + + #endregion Public Instance Constructors + + #region Private Instance Constructors + + // deserialization constructor + private SealedTestException( + SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + + #endregion Private Instance Constructors + } + + #endregion +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs index d4e9c5d..3810209 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs @@ -20,7 +20,7 @@ using System.Collections.Specialized; using NUnit.Framework; - +using Common.Logging.Simple; namespace Common.Logging.Configuration { /// @@ -32,7 +32,7 @@ public class MonoTouchConfigurationReaderTests [Test] public void ReadsAppConfig() { - Assert.AreEqual("FromAppConfig", ((NameValueCollection)new MonoTouchConfigurationReader().GetSection("Settings.bundle/Common.Logging.plist"))["appConfigCheck"]); + Assert.IsNotNull(((ConsoleOutLoggerFactoryAdapter)new MonoTouchConfigurationReader().GetSection("Settings.bundle/Common.Logging.plist"))); } } } \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LogManagerTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LogManagerTests.cs new file mode 100644 index 0000000..9af4fe9 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LogManagerTests.cs @@ -0,0 +1,63 @@ +#region License + +/* + * Copyright © 2002-2007 the original author or authors. + * + * 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.Diagnostics; +using Common.Logging.Configuration; +using Common.Logging.Simple; +using NUnit.Framework; +//using Rhino.Mocks; + +namespace Common.Logging +{ + /// + /// Tests for LogManager that exercise the basic API and check for error conditions. + /// + /// Mark Pollack + [TestFixture] + public class LogManagerTests + { + //public MockRepository mocks; + + [SetUp] + public void SetUp() + { + LogManager.Reset(); + //mocks = new MockRepository(); + } + + [Test] + public void AdapterProperty() + { + ILoggerFactoryAdapter adapter = new NoOpLoggerFactoryAdapter(); + LogManager.Adapter = adapter; + Assert.AreSame(adapter, LogManager.Adapter); + + Assert.Throws(delegate { LogManager.Adapter = null; }); + } + + [Test] + public void ConfigureFromSettings () + { + var logger = LogManager.GetCurrentClassLogger(); + logger.Info("Hi from plist config!"); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LoggingExceptionTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LoggingExceptionTests.cs new file mode 100644 index 0000000..11fb8eb --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LoggingExceptionTests.cs @@ -0,0 +1,42 @@ +#region License + +/* + * Copyright © 2002-2007 the original author or authors. + * + * 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.Reflection; +using NUnit.Framework; + +namespace Common.Logging +{ + /// + /// Test that exceptions declared in Common.Logging meet coding standards. + /// + /// Mark Pollack + /// $Id:$ + [TestFixture] + public class LoggingExceptionTests : ExceptionsTest + { + [TestFixtureSetUp] + public void FixtureSetUp() + { + AssemblyToCheck = Assembly.GetAssembly(typeof (ConfigurationException)); + } + + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/MissingCtorFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/MissingCtorFactoryAdapter.cs new file mode 100644 index 0000000..32132e9 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/MissingCtorFactoryAdapter.cs @@ -0,0 +1,49 @@ +#region License + +/* + * Copyright © 2002-2007 the original author or authors. + * + * 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 Common.Logging +{ + /// + /// Class that does not have constructors used by LogManager to create the adapter. + /// + /// Mark Pollack + /// $Id:$ + public class MissingCtorFactoryAdapter : ILoggerFactoryAdapter + { + private string foo; + + public MissingCtorFactoryAdapter(string foo) + { + this.foo = foo; + } + + public ILog GetLogger(Type type) + { + throw new NotImplementedException(); + } + + public ILog GetLogger(string name) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/MethodInvokePerformanceTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/MethodInvokePerformanceTests.cs new file mode 100644 index 0000000..5e9c06d --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/MethodInvokePerformanceTests.cs @@ -0,0 +1,62 @@ +using System; +using NUnit.Framework; + +namespace Common +{ + internal interface IWriteHandler + { + void PerformanceTestTarget(int z, object message, Exception ex); + } + + [TestFixture, Explicit] + public class MethodInvokePerformanceTests : IWriteHandler + { + private delegate void WriteHandler(int x, object message, Exception ex); + + [Test] + public void DelegatePerformanceTest() + { + int runs = 5000000; + + StopWatch sw; + sw = new StopWatch(); + using(sw.Start("Time:{0}")) + { + for (int i = 0; i < runs; i++) + { + PerformanceTestTarget(1, null, null); + } + } +// Trace.WriteLine( string.Format("Time:{0}", sw.Elapsed.TotalSeconds) ); + + WriteHandler writeHandler = new WriteHandler(PerformanceTestTarget); + using(sw.Start("Time:{0}")) + { + for (int i = 0; i < runs; i++) + { + writeHandler(1, null, null); + } + } +// Trace.WriteLine(string.Format("Time:{0}", sw.Elapsed.TotalSeconds)); + + IWriteHandler writeHandler2 = this; + using(sw.Start("Time:{0}")) + { + for (int i = 0; i < runs; i++) + { + writeHandler2.PerformanceTestTarget(1, null, null); + } + } +// Trace.WriteLine(string.Format("Time:{0}", sw.Elapsed.TotalSeconds)); + } + + public void PerformanceTestTarget(int z, object message, Exception ex) + { + double x = 2.1; + for(int i=0;i<10;i++) + { + x = x * x * x; + } + } + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist index 5443b06..29f6bd0 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist @@ -2,12 +2,10 @@ - appConfigCheck - FromAppConfig dateTimeFormat - + yyyy-MM-dd HH:MI:SS logLevel - LogLevel.Debug + Debug logName log4net for monotouch tests showDateTime diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StandardsComplianceTest.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StandardsComplianceTest.cs new file mode 100644 index 0000000..2b832e0 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StandardsComplianceTest.cs @@ -0,0 +1,109 @@ +#region License + +/* + * Copyright 2004-2008 the original author or authors. + * + * 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 + +#region Imports + +using System; +using System.Reflection; + +#endregion + +namespace Common +{ + /// + /// Base class for tests that check standards compliance. + /// + /// Rick Evans + public abstract class StandardsComplianceTest + { + #region Constructor (s) / Destructor + + /// + /// Creates a new instance of the class. + /// + /// + /// + /// This is an class, and as such has no publicly visible + /// constructors. + /// + /// + protected StandardsComplianceTest() + { + } + + #endregion + + #region Properties + + protected Type CheckedType + { + get { return checkedType; } + set { checkedType = value; } + } + + #endregion + + #region Methods + + private bool IsCheckedType(Type type) + { + if (CheckedType.IsInterface) + { + Type iface = type.GetInterface(CheckedType.Name, false); + return iface != null; + } + else + { + Type baseType = null; + while ((baseType = type.BaseType) != null) + { + if (baseType == CheckedType) + { + return true; + } + type = baseType; + } + } + return false; + } + + protected void ProcessAssembly(Assembly a) + { + foreach (Type t in a.GetTypes()) + { + if (IsCheckedType(t)) + { + CheckStandardsCompliance(a, t); + } + } + } + + protected abstract void CheckStandardsCompliance( + Assembly assembly, Type t); + + #endregion + + #region Fields + + private Type checkedType; + + #endregion + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StopWatch.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StopWatch.cs new file mode 100644 index 0000000..ab09bd0 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StopWatch.cs @@ -0,0 +1,99 @@ +#region License + +/* + * Copyright © 2002-2008 the original author or authors. + * + * 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 + +#region Imports + +using System; + +#endregion + +namespace Common +{ + /// + /// A simple StopWatch implemetion for use in Performance Tests + /// + /// + /// The following example shows the usage: + /// + /// StopWatch watch = new StopWatch(); + /// using (watch.Start("Duration: {0}")) + /// { + /// // do some work... + /// } + /// + /// The format string passed to the start method is used to print the result message. + /// The example above will print Duration: 0.123s. + /// + /// Erich Eichinger + public class StopWatch + { + private DateTime _startTime; + private TimeSpan _elapsed; + + private class Stopper : IDisposable + { + private readonly StopWatch _owner; + private readonly string _format; + + public Stopper(StopWatch owner, string format) + { + _owner = owner; + _format = format; + } + + public void Dispose() + { + _owner.Stop(_format); + GC.SuppressFinalize(this); + } + } + + /// + /// Starts the timer and returns and "handle" that must be disposed to stop the timer. + /// + /// the output format string, that is used to render the result message + /// the handle to dispose for stopping the timer + public IDisposable Start(string outputFormat) + { + Stopper stopper = new Stopper(this, outputFormat); + _startTime = DateTime.Now; + return stopper; + } + + private void Stop(string outputFormat) + { + _elapsed = DateTime.Now.Subtract(_startTime); + if (outputFormat != null) + { + Console.WriteLine(outputFormat, _elapsed); + } + } + + public DateTime StartTime + { + get { return _startTime; } + } + + public TimeSpan Elapsed + { + get { return _elapsed; } + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs index 4d4175e..46529d9 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs @@ -51,7 +51,7 @@ public object GetSection (string sectionName) properties.Add(key.ToString(), nsDict[key].ToString()); } - return properties; + return new ConsoleOutLoggerFactoryAdapter(properties); } } } \ No newline at end of file From 126ea921ed847cb0989f2920cb2c338d270cfc07 Mon Sep 17 00:00:00 2001 From: Daniel-Svensson Date: Wed, 20 Mar 2013 20:40:16 +0100 Subject: [PATCH 06/12] Update TryParseEnum so no VerificationException is thrown on Win 7 x64 with .NET 4.5 installed --- .../Logging/Configuration/ArgUtils.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Common.Logging/Logging/Configuration/ArgUtils.cs b/src/Common.Logging/Logging/Configuration/ArgUtils.cs index fa1cc73..b14b75e 100644 --- a/src/Common.Logging/Logging/Configuration/ArgUtils.cs +++ b/src/Common.Logging/Logging/Configuration/ArgUtils.cs @@ -146,25 +146,25 @@ public static T Coalesce(Predicate predicate, params T[] values) where T : /// the successfully parsed value, otherwise. public static T TryParseEnum(T defaultValue, string stringValue) where T : struct { - if (!typeof(T).IsEnum) + Type enumType = typeof(T); + if (!enumType.IsEnum) { throw new ArgumentException(string.Format("Type '{0}' is not an enum type", typeof(T).FullName)); } - - T result = defaultValue; - if (string.IsNullOrEmpty(stringValue)) - { - return defaultValue; - } + try { - result = (T)Enum.Parse(typeof(T), stringValue, true); + // If a string is specified then try to parse and return it + if (!string.IsNullOrEmpty(stringValue)) + { + return (T)Enum.Parse(enumType, stringValue, true); + } } catch { Trace.WriteLine(string.Format("WARN: failed converting value '{0}' to enum type '{1}'", stringValue, defaultValue.GetType().FullName)); } - return result; + return defaultValue; } /// From 2f05e1078323b2384f9d4e5df0f8e02b413a123f Mon Sep 17 00:00:00 2001 From: Stephen Bohlen Date: Sat, 13 Jul 2013 05:23:15 -0400 Subject: [PATCH 07/12] minor refactoring and added license header --- .../Logging/Simple/ExceptionFormatter.cs | 66 ++++++++++++------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/src/Common.Logging/Logging/Simple/ExceptionFormatter.cs b/src/Common.Logging/Logging/Simple/ExceptionFormatter.cs index 9218979..6a130cc 100644 --- a/src/Common.Logging/Logging/Simple/ExceptionFormatter.cs +++ b/src/Common.Logging/Logging/Simple/ExceptionFormatter.cs @@ -1,4 +1,22 @@ -// Copyright © Anton Paar GmbH, 2004-2013 +#region License + +/* + * Copyright © 2002-2013 the original author or authors. + * + * 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; @@ -14,9 +32,9 @@ namespace Common.Logging.Simple internal static class ExceptionFormatter { // constants - private const String DELIMITER_LINE = + private const String STANDARD_DELIMETER = "================================================================================\r\n"; - private const String INNERMOST_DELIMITER_LINE = + private const String INNERMOST_DELIMETER = "=======================================================(inner most exception)===\r\n"; internal static String Format(Exception exception) @@ -43,26 +61,26 @@ internal static String Format(Exception exception, IFormatProvider formatProvide for (Int32 i = 1; exceptionStack.Count > 0; i++) { currentException = (Exception)exceptionStack.Pop(); - _FormatSingleException(formatProvider, sb, currentException, i); + FormatSingleException(formatProvider, sb, currentException, i); } // that's it; return result return sb.ToString(); } - private static void _FormatSingleException(IFormatProvider formatProvider, StringBuilder sb, Exception exception, + private static void FormatSingleException(IFormatProvider formatProvider, StringBuilder sb, Exception exception, Int32 exceptionIndex) { - _OutputHeader(formatProvider, sb, exception, exceptionIndex); - _OutputDetails(formatProvider, sb, exception); - _OutputMessage(formatProvider, sb, exception); - _OutputProperties(formatProvider, sb, exception); - _OutputData(formatProvider, sb, exception); - _OutputStackTrace(formatProvider, sb, exception); - sb.Append(DELIMITER_LINE); + OutputHeader(formatProvider, sb, exception, exceptionIndex); + OutputDetails(formatProvider, sb, exception); + OutputMessage(formatProvider, sb, exception); + OutputProperties(formatProvider, sb, exception); + OutputData(formatProvider, sb, exception); + OutputStackTrace(formatProvider, sb, exception); + sb.Append(STANDARD_DELIMETER); } - private static void _OutputHeader(IFormatProvider formatProvider, StringBuilder sb, Exception exception, + private static void OutputHeader(IFormatProvider formatProvider, StringBuilder sb, Exception exception, Int32 exceptionIndex) { // output header: @@ -71,13 +89,13 @@ private static void _OutputHeader(IFormatProvider formatProvider, StringBuilder // (index) exception-type-name // ================================================================================ // - sb.Append(exceptionIndex == 1 ? INNERMOST_DELIMITER_LINE : DELIMITER_LINE); + sb.Append(exceptionIndex == 1 ? INNERMOST_DELIMETER : STANDARD_DELIMETER); sb.AppendFormat(formatProvider, " ({0}) {1}\r\n", exceptionIndex, exception.GetType().FullName); - sb.Append(DELIMITER_LINE); + sb.Append(STANDARD_DELIMETER); } - private static void _OutputDetails(IFormatProvider formatProvider, StringBuilder sb, Exception exception) + private static void OutputDetails(IFormatProvider formatProvider, StringBuilder sb, Exception exception) { // output exception details: // @@ -92,8 +110,8 @@ private static void _OutputDetails(IFormatProvider formatProvider, StringBuilder String assemblyName, assemblyModuleName, typeName, methodName; String source, helplink; - _SafeGetTargetSiteInfo(exception, out assemblyName, out assemblyModuleName, out typeName, out methodName); - _SafeGetSourceAndHelplink(exception, out source, out helplink); + SafeGetTargetSiteInfo(exception, out assemblyName, out assemblyModuleName, out typeName, out methodName); + SafeGetSourceAndHelplink(exception, out source, out helplink); sb.AppendFormat(formatProvider, "Method : {0}\r\n" + @@ -109,7 +127,7 @@ private static void _OutputDetails(IFormatProvider formatProvider, StringBuilder helplink); } - private static void _OutputMessage(IFormatProvider formatProvider, StringBuilder sb, Exception exception) + private static void OutputMessage(IFormatProvider formatProvider, StringBuilder sb, Exception exception) { // output exception message: // @@ -120,7 +138,7 @@ private static void _OutputMessage(IFormatProvider formatProvider, StringBuilder exception.Message); } - private static void _OutputProperties(IFormatProvider formatProvider, StringBuilder sb, Exception exception) + private static void OutputProperties(IFormatProvider formatProvider, StringBuilder sb, Exception exception) { // output exception properties: // @@ -168,7 +186,7 @@ private static void _OutputProperties(IFormatProvider formatProvider, StringBuil } } - private static void _OutputData(IFormatProvider formatProvider, StringBuilder sb, Exception exception) + private static void OutputData(IFormatProvider formatProvider, StringBuilder sb, Exception exception) { // output exception properties: // @@ -187,7 +205,7 @@ private static void _OutputData(IFormatProvider formatProvider, StringBuilder sb } } - private static void _OutputStackTrace(IFormatProvider formatProvider, StringBuilder sb, Exception exception) + private static void OutputStackTrace(IFormatProvider formatProvider, StringBuilder sb, Exception exception) { // output stack trace: // @@ -200,7 +218,7 @@ private static void _OutputStackTrace(IFormatProvider formatProvider, StringBuil exception.StackTrace); } - private static void _SafeGetTargetSiteInfo(Exception exception, out String assemblyName, out String assemblyModulePath, + private static void SafeGetTargetSiteInfo(Exception exception, out String assemblyName, out String assemblyModulePath, out String typeName, out String methodName) { assemblyName = ""; @@ -225,7 +243,7 @@ private static void _SafeGetTargetSiteInfo(Exception exception, out String assem } } - private static void _SafeGetSourceAndHelplink(Exception exception, out String source, out String helplink) + private static void SafeGetSourceAndHelplink(Exception exception, out String source, out String helplink) { source = exception.Source; helplink = exception.HelpLink; From fbcc1429357a00ef4db9cc95783612561ea9312d Mon Sep 17 00:00:00 2001 From: adamnation Date: Fri, 25 Jan 2013 20:07:18 -0800 Subject: [PATCH 08/12] initial project creation, removing System.Configuration dependency, adding MonoTouch - specific config reader --- .gitignore | 2 +- .../Common.Logging.MonoTouch.sln | 20 + .../Common.Logging.MonoTouch/AssemblyDoc.cs | 31 + .../Common.Logging.MonoTouch/AssemblyInfo.cs | 5 + .../Common.Logging.MonoTouch.csproj | 84 ++ .../Common.Logging.MonoTouch/LogManager.cs | 333 ++++++ .../Logging/Configuration/ArgUtils.cs | 316 +++++ .../Logging/Configuration/LogSetting.cs | 77 ++ .../MonoTouchConfigurationReader.cs | 48 + .../Logging/Configuration/NamespaceDoc.cs | 31 + .../Logging/ConfigurationException.cs | 84 ++ .../Logging/ConfigurationSectionHandler.cs | 232 ++++ .../Logging/CoverageExcludeAttribute.cs | 32 + .../AbstractCachingLoggerFactoryAdapter.cs | 132 +++ .../Logging/Factory/AbstractLogger.cs | 1033 +++++++++++++++++ .../Logging/Factory/NamespaceDoc.cs | 31 + .../Logging/FormatMessageHandler.cs | 32 + .../Logging/IConfigurationReader.cs | 49 + .../Common.Logging.MonoTouch/Logging/ILog.cs | 649 +++++++++++ .../Logging/ILoggerFactoryAdapter.cs | 49 + .../Logging/LogLevel.cs | 62 + .../Logging/LogManager.cs | 333 ++++++ .../Logging/MonoNet/CollectionsUtil.cs | 64 + .../Logging/NamespaceDoc.cs | 31 + .../Logging/Simple/AbstractSimpleLogger.cs | 263 +++++ .../AbstractSimpleLoggerFactoryAdapter.cs | 168 +++ .../Logging/Simple/ConsoleOutLogger.cs | 64 + .../Simple/ConsoleOutLoggerFactoryAdapter.cs | 81 ++ .../Logging/Simple/NamespaceDoc.cs | 31 + .../Logging/Simple/NoOpLogger.cs | 731 ++++++++++++ .../Simple/NoOpLoggerFactoryAdapter.cs | 102 ++ .../DefaultConfigurationReader.cs | 2 +- .../Logging/IConfigurationReader.cs | 2 - src/CommonAssemblyInfo.cs | 4 +- 34 files changed, 5202 insertions(+), 6 deletions(-) create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyDoc.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyInfo.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/LogManager.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/ArgUtils.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/LogSetting.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/NamespaceDoc.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationException.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationSectionHandler.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/CoverageExcludeAttribute.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractCachingLoggerFactoryAdapter.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractLogger.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/NamespaceDoc.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/FormatMessageHandler.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/IConfigurationReader.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILog.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILoggerFactoryAdapter.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogLevel.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogManager.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/MonoNet/CollectionsUtil.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/NamespaceDoc.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLogger.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLogger.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NamespaceDoc.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLogger.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLoggerFactoryAdapter.cs diff --git a/.gitignore b/.gitignore index 44c4c21..27989fc 100644 --- a/.gitignore +++ b/.gitignore @@ -47,4 +47,4 @@ src/Common.Logging.Log4Net129/Common.Logging.Log4Net129.xml src/Common.Logging.Log4Net1211/Common.Logging.Log4Net1211.xml src/Common.Logging.NLog10/Common.Logging.NLog10.xml src/Common.Logging.NLog20/Common.Logging.NLog20.xml -src/Common.Logging/Common.Logging.xml \ No newline at end of file +src/Common.Logging/Common.Logging.xml diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln new file mode 100644 index 0000000..b4b3f8d --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.MonoTouch", "Common.Logging.MonoTouch\Common.Logging.MonoTouch.csproj", "{DD9F81C2-BA9A-4212-9249-2300C62AFF6F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(MonoDevelopProperties) = preSolution + StartupItem = Common.Logging.MonoTouch\Common.Logging.MonoTouch.csproj + EndGlobalSection +EndGlobal diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyDoc.cs new file mode 100644 index 0000000..12ad8f6 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyDoc.cs @@ -0,0 +1,31 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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 Common.Logging; + +/// +/// This assembly contains the core functionality of the Common.Logging framework. +/// In particular, checkout and for usage information. +/// +[CoverageExclude] +internal static class AssemblyDoc +{ + // serves as assembly summary for NDoc3 (http://ndoc3.sourceforge.net) +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyInfo.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyInfo.cs new file mode 100644 index 0000000..6a6d886 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyInfo.cs @@ -0,0 +1,5 @@ +using System.Reflection; +using System.Security; + +[assembly: AssemblyProduct("Common Logging Framework")] +[assembly: SecurityTransparent] \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj new file mode 100644 index 0000000..7f9b8a8 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj @@ -0,0 +1,84 @@ + + + + Debug + AnyCPU + 10.0.0 + 2.0 + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F} + {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Common.Logging.MonoTouch + Resources + Common.Logging.MonoTouch + + + True + full + False + bin\Debug + DEBUG; + prompt + 4 + False + + + none + True + bin\Release + prompt + 4 + False + + + + + + + + + + + + + + + + + + + + + + + + + + + ILoggerFactoryAdapter.cs + + + + + + CommonAssemblyInfo.cs + + + + + Code + + + + + + Code + + + + + + + + + \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/LogManager.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/LogManager.cs new file mode 100644 index 0000000..2f3b306 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/LogManager.cs @@ -0,0 +1,333 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Configuration; +using System.Diagnostics; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Security; +using System.Security.Permissions; +using Common.Logging.Simple; +using Common.Logging.Configuration; + +namespace Common.Logging +{ + /// + /// Use the LogManager's or + /// methods to obtain instances for logging. + /// + /// + /// For configuring the underlying log system using application configuration, see the example + /// at . + /// For configuring programmatically, see the example section below. + /// + /// + /// The example below shows the typical use of LogManager to obtain a reference to a logger + /// and log an exception: + /// + /// + /// ILog log = LogManager.GetLogger(this.GetType()); + /// ... + /// try + /// { + /// /* .... */ + /// } + /// catch(Exception ex) + /// { + /// log.ErrorFormat("Hi {0}", ex, "dude"); + /// } + /// + /// + /// The example below shows programmatic configuration of the underlying log system: + /// + /// + /// // create properties + /// NameValueCollection properties = new NameValueCollection(); + /// properties["showDateTime"] = "true"; + /// + /// // set Adapter + /// Common.Logging.LogManager.Adapter = new + /// Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(properties); + /// + /// + /// + /// + /// + /// + /// + /// Gilles Bayon + public static class LogManager + { + /// + /// The name of the default configuration section to read settings from. + /// + /// + /// You can always change the source of your configuration settings by setting another instance + /// on . + /// + public static readonly string COMMON_LOGGING_SECTION = "common/logging"; + + private static IConfigurationReader _configurationReader; + private static ILoggerFactoryAdapter _adapter; + private static readonly object _loadLock = new object(); + + /// + /// Performs static 1-time init of LogManager by calling + /// + static LogManager() + { + Reset(); + } + + /// + /// Reset the infrastructure to its default settings. This means, that configuration settings + /// will be re-read from section <common/logging> of your app.config. + /// + /// + /// This is mainly used for unit testing, you wouldn't normally use this in your applications.
+ /// Note: instances already handed out from this LogManager are not(!) affected. + /// Resetting LogManager only affects new instances being handed out. + ///
+ public static void Reset() + { + Reset(new DefaultConfigurationReader()); + } + + /// + /// Reset the infrastructure to its default settings. This means, that configuration settings + /// will be re-read from section <common/logging> of your app.config. + /// + /// + /// This is mainly used for unit testing, you wouldn't normally use this in your applications.
+ /// Note: instances already handed out from this LogManager are not(!) affected. + /// Resetting LogManager only affects new instances being handed out. + ///
+ /// + /// the instance to obtain settings for + /// re-initializing the LogManager. + /// + public static void Reset(IConfigurationReader reader) + { + lock (_loadLock) + { + if (reader == null) + { + throw new ArgumentNullException("reader"); + } + _configurationReader = reader; + _adapter = null; + } + } + + /// + /// Gets the configuration reader used to initialize the LogManager. + /// + /// Primarily used for testing purposes but maybe useful to obtain configuration + /// information from some place other than the .NET application configuration file. + /// The configuration reader. + public static IConfigurationReader ConfigurationReader + { + get + { + return _configurationReader; + } + } + + /// + /// Gets or sets the adapter. + /// + /// The adapter. + public static ILoggerFactoryAdapter Adapter + { + get + { + if (_adapter == null) + { + lock (_loadLock) + { + if (_adapter == null) + { + _adapter = BuildLoggerFactoryAdapter(); + } + } + } + return _adapter; + } + set + { + if (value == null) + { + throw new ArgumentNullException("Adapter"); + } + + lock (_loadLock) + { + _adapter = value; + } + } + } + + /// + /// Gets the logger by calling + /// on the currently configured using the type of the calling class. + /// + /// + /// This method needs to inspect the in order to determine the calling + /// class. This of course comes with a performance penalty, thus you shouldn't call it too + /// often in your application. + /// + /// + /// the logger instance obtained from the current + [MethodImpl(MethodImplOptions.NoInlining)] + public static ILog GetCurrentClassLogger() + { + StackFrame frame = new StackFrame(1, false); + ILoggerFactoryAdapter adapter = Adapter; + MethodBase method = frame.GetMethod(); + Type declaringType = method.DeclaringType; + return adapter.GetLogger(declaringType); + } + + /// + /// Gets the logger by calling + /// on the currently configured using the specified type. + /// + /// the logger instance obtained from the current + public static ILog GetLogger() + { + return Adapter.GetLogger(typeof(T)); + } + + /// + /// Gets the logger by calling + /// on the currently configured using the specified type. + /// + /// The type. + /// the logger instance obtained from the current + public static ILog GetLogger(Type type) + { + return Adapter.GetLogger(type); + } + + + /// + /// Gets the logger by calling + /// on the currently configured using the specified name. + /// + /// The name. + /// the logger instance obtained from the current + public static ILog GetLogger(string name) + { + return Adapter.GetLogger(name); + } + + + /// + /// Builds the logger factory adapter. + /// + /// a factory adapter instance. Is never null. + private static ILoggerFactoryAdapter BuildLoggerFactoryAdapter() + { + object sectionResult = null; + + ArgUtils.Guard(delegate + { + sectionResult = ConfigurationReader.GetSection(COMMON_LOGGING_SECTION); + } + , "Failed obtaining configuration for Common.Logging from configuration section 'common/logging'."); + + // configuration reader returned + if (sectionResult == null) + { + string message = (ConfigurationReader.GetType() == typeof(DefaultConfigurationReader)) + ? string.Format("no configuration section <{0}> found - suppressing logging output", COMMON_LOGGING_SECTION) + : string.Format("Custom ConfigurationReader '{0}' returned - suppressing logging output", ConfigurationReader.GetType().FullName); + Trace.WriteLine(message); + ILoggerFactoryAdapter defaultFactory = new NoOpLoggerFactoryAdapter(); + return defaultFactory; + } + + // ready to use ILoggerFactoryAdapter? + if (sectionResult is ILoggerFactoryAdapter) + { + Trace.WriteLine(string.Format("Using ILoggerFactoryAdapter returned from custom ConfigurationReader '{0}'", ConfigurationReader.GetType().FullName)); + return (ILoggerFactoryAdapter)sectionResult; + } + + // ensure what's left is a LogSetting instance + ArgUtils.Guard(delegate + { + ArgUtils.AssertIsAssignable("sectionResult", sectionResult.GetType()); + } + , "ConfigurationReader {0} returned unknown settings instance of type {1}" + , ConfigurationReader.GetType().FullName, sectionResult.GetType().FullName); + + ILoggerFactoryAdapter adapter = null; + ArgUtils.Guard(delegate + { + adapter = BuildLoggerFactoryAdapterFromLogSettings((LogSetting)sectionResult); + } + , "Failed creating LoggerFactoryAdapter from settings"); + + return adapter; + } + + /// + /// Builds a instance from the given + /// using . + /// + /// + /// the instance. Is never null + private static ILoggerFactoryAdapter BuildLoggerFactoryAdapterFromLogSettings(LogSetting setting) + { + ArgUtils.AssertNotNull("setting", setting); + // already ensured by LogSetting + // AssertArgIsAssignable("setting.FactoryAdapterType", setting.FactoryAdapterType + // , "Specified FactoryAdapter does not implement {0}. Check implementation of class {1}" + // , typeof(ILoggerFactoryAdapter).FullName + // , setting.FactoryAdapterType.AssemblyQualifiedName); + + ILoggerFactoryAdapter adapter = null; + + ArgUtils.Guard(delegate + { + if (setting.Properties != null + && setting.Properties.Count > 0) + { + object[] args = { setting.Properties }; + + adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType, args); + } + else + { + adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType); + } + } + , "Unable to create instance of type {0}. Possible explanation is lack of zero arg and single arg NameValueCollection constructors" + , setting.FactoryAdapterType.FullName + ); + + // make sure + ArgUtils.AssertNotNull("adapter", adapter, "Activator.CreateInstance() returned "); + return adapter; + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/ArgUtils.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/ArgUtils.cs new file mode 100644 index 0000000..52b615e --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/ArgUtils.cs @@ -0,0 +1,316 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Diagnostics; + +namespace Common.Logging.Configuration +{ + /// + /// Various utility methods for using during factory and logger instance configuration + /// + /// Erich Eichinger + public static class ArgUtils + { + /// + /// A delegate converting a string representation into the target type + /// + public delegate T ParseHandler(string strValue); + + private static readonly Hashtable s_parsers; + + /// + /// Initialize all members before any of this class' methods can be accessed (avoids beforeFieldInit) + /// + static ArgUtils() + { + s_parsers = new Hashtable(); + RegisterTypeParser(delegate(string s) { return Convert.ToBoolean(s); }); + RegisterTypeParser(delegate(string s) { return Convert.ToInt16(s); }); + RegisterTypeParser(delegate(string s) { return Convert.ToInt32(s); }); + RegisterTypeParser(delegate(string s) { return Convert.ToInt64(s); }); + RegisterTypeParser(delegate(string s) { return Convert.ToSingle(s); }); + RegisterTypeParser(delegate(string s) { return Convert.ToDouble(s); }); + RegisterTypeParser(delegate(string s) { return Convert.ToDecimal(s); }); + } + + /// + /// Adds the parser to the list of known type parsers. + /// + /// + /// .NET intrinsic types are pre-registerd: short, int, long, float, double, decimal, bool + /// + public static void RegisterTypeParser(ParseHandler parser) + { + s_parsers[typeof(T)] = parser; + } + + /// + /// Retrieves the named value from the specified . + /// + /// may be null + /// the value's key + /// if is not null, the value returned by values[name]. null otherwise. + public static string GetValue(NameValueCollection values, string name) + { + return GetValue(values, name, null); + } + + /// + /// Retrieves the named value from the specified . + /// + /// may be null + /// the value's key + /// the default value, if not found + /// if is not null, the value returned by values[name]. null otherwise. + public static string GetValue(NameValueCollection values, string name, string defaultValue) + { + if (values != null) + { + foreach (string key in values.AllKeys) + { + if (string.Compare(name, key, true) == 0) + { + return values[name]; + } + } + } + return defaultValue; + } + + /// + /// Returns the first nonnull, nonempty value among its arguments. + /// + /// + /// Returns null, if the initial list was null or empty. + /// + /// + public static string Coalesce(params string[] values) + { + return Coalesce(delegate(string v) { return !string.IsNullOrEmpty(v); }, values); + } + + /// + /// Returns the first nonnull, nonempty value among its arguments. + /// + /// + /// Also + /// + public static T Coalesce(Predicate predicate, params T[] values) where T : class + { + if (values == null || values.Length == 0) + { + return null; + } + + if (predicate == null) + { + predicate = delegate(T v) { return v != null; }; + } + + for (int i = 0; i < values.Length; i++) + { + T val = values[i]; + if (predicate(val)) + { + return val; + } + } + return null; + } + + /// + /// Tries parsing into an enum of the type of . + /// + /// the default value to return if parsing fails + /// the string value to parse + /// the successfully parsed value, otherwise. + public static T TryParseEnum(T defaultValue, string stringValue) where T : struct + { + if (!typeof(T).IsEnum) + { + throw new ArgumentException(string.Format("Type '{0}' is not an enum type", typeof(T).FullName)); + } + + T result = defaultValue; + if (string.IsNullOrEmpty(stringValue)) + { + return defaultValue; + } + try + { + result = (T)Enum.Parse(typeof(T), stringValue, true); + } + catch + { + Console.Error.WriteLine(string.Format("WARN: failed converting value '{0}' to enum type '{1}'", stringValue, defaultValue.GetType().FullName)); + } + return result; + } + + /// + /// Tries parsing into the specified return type. + /// + /// the default value to return if parsing fails + /// the string value to parse + /// the successfully parsed value, otherwise. + public static T TryParse(T defaultValue, string stringValue) + { + T result = defaultValue; + if (string.IsNullOrEmpty(stringValue)) + { + return defaultValue; + } + + ParseHandler parser = s_parsers[typeof(T)] as ParseHandler; + if (parser == null) + { + throw new ArgumentException(string.Format("There is no parser registered for type {0}", typeof(T).FullName)); + } + + try + { + result = parser(stringValue); + } + catch + { + Console.Error.WriteLine(string.Format("WARN: failed converting value '{0}' to type '{1}' - returning default '{2}'", stringValue, typeof(T).FullName, result)); + } + return result; + } + + /// + /// Throws a if is null. + /// + public static T AssertNotNull(string paramName, T val) where T : class + { + if (ReferenceEquals(val, null)) + { + throw new ArgumentNullException(paramName); + } + return val; + } + + /// + /// Throws a if is null. + /// + public static T AssertNotNull(string paramName, T val, string messageFormat, params object[] args) where T : class + { + if (ReferenceEquals(val, null)) + { + throw new ArgumentNullException(paramName, string.Format(messageFormat, args)); + } + return val; + } + + /// + /// Throws a if an object of type is not + /// assignable to type . + /// + public static Type AssertIsAssignable(string paramName, Type valType) + { + return AssertIsAssignable(paramName + , valType + , string.Format("Type '{0}' of parameter '{1}' is not assignable to target type '{2}'" + , valType == null ? "" : valType.AssemblyQualifiedName + , paramName + , typeof(T).AssemblyQualifiedName) + ); + } + + /// + /// Throws a if an object of type is not + /// assignable to type . + /// + public static Type AssertIsAssignable(string paramName, Type valType, string messageFormat, params object[] args) + { + if (valType == null) + { + throw new ArgumentNullException("valType"); + } + + if (!typeof(T).IsAssignableFrom(valType)) + { + throw new ArgumentOutOfRangeException(paramName, valType, string.Format(messageFormat, args)); + } + return valType; + } + + /// + /// An anonymous action delegate with no arguments and no return value. + /// + /// + public delegate void Action(); + + /// + /// Ensures any exception thrown by the given is wrapped with an + /// . + /// + /// + /// If already throws a ConfigurationException, it will not be wrapped. + /// + /// the action to execute + /// the message to be set on the thrown + /// args to be passed to to format the message + public static void Guard(Action action, string messageFormat, params object[] args) + { + Guard(delegate + { + action(); + return 0; + } + , messageFormat, args); + } + + /// + /// An anonymous action delegate with no arguments and no return value. + /// + /// + public delegate T Function(); + + /// + /// Ensures any exception thrown by the given is wrapped with an + /// . + /// + /// + /// If already throws a ConfigurationException, it will not be wrapped. + /// + /// the action to execute + /// the message to be set on the thrown + /// args to be passed to to format the message + public static T Guard(Function function, string messageFormat, params object[] args) + { + try + { + return function(); + } + catch (ConfigurationException) + { + throw; + } + catch (Exception ex) + { + throw new ConfigurationException(string.Format(messageFormat, args), ex); + } + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/LogSetting.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/LogSetting.cs new file mode 100644 index 0000000..d54a622 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/LogSetting.cs @@ -0,0 +1,77 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 Common.Logging.Configuration +{ + /// + /// Container used to hold configuration information from config file. + /// + /// Gilles Bayon + public class LogSetting + { + #region Fields + + private readonly Type _factoryAdapterType = null; + private readonly NameValueCollection _properties = null; + + #endregion + + /// + /// + /// + /// + /// The type + /// that will be used for creating + /// + /// + /// Additional user supplied properties that are passed to the + /// 's constructor. + /// + public LogSetting(Type factoryAdapterType, NameValueCollection properties) + { + ArgUtils.AssertNotNull("factoryAdapterType", factoryAdapterType); + ArgUtils.AssertIsAssignable("factoryAdapterType", factoryAdapterType + , "Type {0} does not implement {1}", factoryAdapterType.AssemblyQualifiedName, typeof(ILoggerFactoryAdapter).FullName); + + _factoryAdapterType = factoryAdapterType; + _properties = properties; + } + + /// + /// The type that will be used for creating + /// instances. + /// + public Type FactoryAdapterType + { + get { return _factoryAdapterType; } + } + + /// + /// Additional user supplied properties that are passed to the 's constructor. + /// + public NameValueCollection Properties + { + get { return _properties; } + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs new file mode 100644 index 0000000..3aed086 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs @@ -0,0 +1,48 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 MonoTouch.Foundation; + +namespace Common.Logging.Configuration +{ + /// + /// MonoTouch implementation of configuration reader. Each section corresponds to a plist on the device. + /// + /// adamnation + public class MonoTouchConfigurationReader : IConfigurationReader + { + /// + /// Parses the configuration section and returns the resulting object. + /// + /// Path to the plist on the device + /// + /// NSDictionary of the settings in the plist. + /// + /// + ///

+ /// Primary purpose of this method is to allow us to load settings from a plist on the device. + ///

+ ///
+ /// + public object GetSection(string sectionName) + { + return new NSDictionary (NSBundle.MainBundle.PathForResource (sectionName, null)); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/NamespaceDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/NamespaceDoc.cs new file mode 100644 index 0000000..fa66a7e --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/NamespaceDoc.cs @@ -0,0 +1,31 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 + +namespace Common.Logging.Configuration +{ + /// + /// This namespace contains various utility classes. + /// + [CoverageExclude] + internal static class NamespaceDoc + { + // serves as namespace summary for NDoc3 (http://ndoc3.sourceforge.net) + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationException.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationException.cs new file mode 100644 index 0000000..6254b54 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationException.cs @@ -0,0 +1,84 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Runtime.Serialization; + +namespace Common.Logging +{ + /// + /// The exception that is thrown when a configuration system error has occurred with Common.Logging + /// + /// Mark Pollack + [Serializable] + public class ConfigurationException : ApplicationException + { + #region Constructor (s) / Destructor + + /// Creates a new instance of the ObjectsException class. + public ConfigurationException() + { + } + + /// + /// Creates a new instance of the ConfigurationException class. with the specified message. + /// + /// + /// A message about the exception. + /// + public ConfigurationException(string message) : base(message) + { + } + + /// + /// Creates a new instance of the ConfigurationException class with the specified message + /// and root cause. + /// + /// + /// A message about the exception. + /// + /// + /// The root exception that is being wrapped. + /// + public ConfigurationException(string message, Exception rootCause) + : base(message, rootCause) + { + } + + /// + /// Creates a new instance of the ConfigurationException class. + /// + /// + /// The + /// that holds the serialized object data about the exception being thrown. + /// + /// + /// The + /// that contains contextual information about the source or destination. + /// + protected ConfigurationException( + SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationSectionHandler.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationSectionHandler.cs new file mode 100644 index 0000000..81262e5 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationSectionHandler.cs @@ -0,0 +1,232 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Runtime.CompilerServices; +using System.Xml; +using Common.Logging.Simple; +using Common.Logging.Configuration; + +namespace Common.Logging +{ + /// + /// Used in an application's configuration file (App.Config or Web.Config) to configure the logging subsystem. + /// + /// + /// An example configuration section that writes log messages to the Console using the + /// built-in Console Logger. + /// + /// <configuration> + /// <configSections> + /// <sectionGroup name="common"> + /// <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> + /// </sectionGroup> + /// </configSections> + /// <common> + /// <logging> + /// <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging"> + /// <arg key="showLogName" value="true" /> + /// <arg key="showDataTime" value="true" /> + /// <arg key="level" value="ALL" /> + /// <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" /> + /// </factoryAdapter> + /// </logging> + /// </common> + /// </configuration> + /// + /// + public class ConfigurationSectionHandler : IConfigurationSectionHandler + { + + #region Fields + + private static readonly string LOGFACTORYADAPTER_ELEMENT = "factoryAdapter"; + 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 + + /// + /// Ensure static fields get initialized before any class member + /// can be accessed (avoids beforeFieldInit) + /// + static ConfigurationSectionHandler() + { } + + /// + /// Constructor + /// + public ConfigurationSectionHandler() + { } + + /// + /// Retrieves the of the logger the use by looking at the logFactoryAdapter element + /// of the logging configuration element. + /// + /// + /// + /// A object containing the specified type that implements + /// along with zero or more properties that will be + /// passed to the logger factory adapter's constructor as an . + /// + 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 + { + if (String.Compare(factoryTypeString, "CONSOLE", true) == 0) + { + factoryType = typeof(ConsoleOutLoggerFactoryAdapter); + } + else if (String.Compare(factoryTypeString, "TRACE", true) == 0) + { + factoryType = typeof(TraceLoggerFactoryAdapter); + } + else if (String.Compare(factoryTypeString, "NOOP", true) == 0) + { + factoryType = typeof(NoOpLoggerFactoryAdapter); + } + else + { + 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 = null; + properties = new NameValueCollection(); // defaults to case-insensitive keys + + 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); + } + + /// + /// Verifies that the logFactoryAdapter element appears once in the configuration section. + /// + /// settings of a parent section - atm this must always be null + /// Additional information about the configuration process. + /// The configuration section to apply an XPath query too. + /// + /// A object containing the specified logFactoryAdapter type + /// along with user supplied configuration properties. + /// + public LogSetting Create(LogSetting parent, object configContext, XmlNode section) + { + if (parent != null) + { + throw new ConfigurationException("parent configuration sections are not allowed"); + } + + int logFactoryElementsCount = section.SelectNodes(LOGFACTORYADAPTER_ELEMENT).Count; + + if (logFactoryElementsCount > 1) + { + throw new ConfigurationException("Only one element allowed"); + } + else if (logFactoryElementsCount == 1) + { + return ReadConfiguration(section); + } + else + { + return null; + } + } + + #region IConfigurationSectionHandler Members + + /// + /// Verifies that the logFactoryAdapter element appears once in the configuration section. + /// + /// The parent of the current item. + /// Additional information about the configuration process. + /// The configuration section to apply an XPath query too. + /// + /// A object containing the specified logFactoryAdapter type + /// along with user supplied configuration properties. + /// + object IConfigurationSectionHandler.Create(object parent, object configContext, XmlNode section) + { + return Create(parent as LogSetting, configContext, section); + } + + #endregion + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/CoverageExcludeAttribute.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/CoverageExcludeAttribute.cs new file mode 100644 index 0000000..60e7650 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/CoverageExcludeAttribute.cs @@ -0,0 +1,32 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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; + +/// +/// Indicates classes or members to be ignored by NCover +/// +/// +/// Note, the name is chosen, because TestDriven.NET uses it as //ea argument to "Test With... Coverage" +/// +/// Erich Eichinger +[AttributeUsage(AttributeTargets.All)] +internal class CoverageExcludeAttribute : Attribute +{} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractCachingLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractCachingLoggerFactoryAdapter.cs new file mode 100644 index 0000000..6a5fc61 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractCachingLoggerFactoryAdapter.cs @@ -0,0 +1,132 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 Common.Logging.Factory +{ + /// + /// An implementation of that caches loggers handed out by this factory. + /// + /// + /// Implementors just need to override . + /// + /// Erich Eichinger + public abstract class AbstractCachingLoggerFactoryAdapter : ILoggerFactoryAdapter + { + private readonly Hashtable _cachedLoggers; + + /// + /// Creates a new instance, the logger cache being case-sensitive. + /// + protected AbstractCachingLoggerFactoryAdapter():this(true) + {} + + /// + /// Creates a new instance, the logger cache being . + /// + /// + protected AbstractCachingLoggerFactoryAdapter(bool caseSensitiveLoggerCache) + { + _cachedLoggers = (caseSensitiveLoggerCache) + ? new Hashtable() + : CollectionsUtil.CreateCaseInsensitiveHashtable(); + } + + /// + /// Purges all loggers from cache + /// + protected void ClearLoggerCache() + { + lock (_cachedLoggers) + { + _cachedLoggers.Clear(); + } + } + + /// + /// Create the specified named logger instance + /// + /// + /// Derived factories need to implement this method to create the + /// actual logger instance. + /// + protected abstract ILog CreateLogger(string name); + + #region ILoggerFactoryAdapter Members + + /// + /// Get a ILog instance by . + /// + /// Usually the of the current class. + /// + /// An ILog instance either obtained from the internal cache or created by a call to . + /// + public ILog GetLogger(Type type) + { + return GetLoggerInternal(type.FullName); + } + + /// + /// Get a ILog instance by name. + /// + /// Usually a 's Name or FullName property. + /// + /// An ILog instance either obtained from the internal cache or created by a call to . + /// + public ILog GetLogger(string name) + { + return GetLoggerInternal(name); + } + + /// + /// Get or create a ILog instance by name. + /// + /// Usually a 's Name or FullName property. + /// + /// An ILog instance either obtained from the internal cache or created by a call to . + /// + private ILog GetLoggerInternal(string name) + { + ILog log = _cachedLoggers[name] as ILog; + if (log == null) + { + lock (_cachedLoggers) + { + log = _cachedLoggers[name] as ILog; + if (log == null) + { + log = CreateLogger(name); + if (log == null) + { + throw new ArgumentException(string.Format("{0} returned null on creating logger instance for name {1}", this.GetType().FullName, name)); + } + _cachedLoggers.Add(name, log); + } + } + } + return log; + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractLogger.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractLogger.cs new file mode 100644 index 0000000..012a20b --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractLogger.cs @@ -0,0 +1,1033 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 FormatMessageCallback = System.Action; + +namespace Common.Logging.Factory +{ + /// + /// Provides base implementation suitable for almost all logger adapters + /// + /// Erich Eichinger + [Serializable] + public abstract class AbstractLogger : ILog + { + #region FormatMessageCallbackFormattedMessage + + /// + /// Format message on demand. + /// + protected class FormatMessageCallbackFormattedMessage + { + private volatile string cachedMessage; + + private readonly IFormatProvider formatProvider; + private readonly FormatMessageCallback formatMessageCallback; + + /// + /// Initializes a new instance of the class. + /// + /// The format message callback. + public FormatMessageCallbackFormattedMessage(FormatMessageCallback formatMessageCallback) + { + this.formatMessageCallback = formatMessageCallback; + } + + /// + /// Initializes a new instance of the class. + /// + /// The format provider. + /// The format message callback. + public FormatMessageCallbackFormattedMessage(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + this.formatProvider = formatProvider; + this.formatMessageCallback = formatMessageCallback; + } + + /// + /// Calls and returns result. + /// + /// + public override string ToString() + { + if (cachedMessage == null && formatMessageCallback != null) + { + formatMessageCallback(FormatMessage); + } + return cachedMessage; + } + + private string FormatMessage(string format, params object[] args) + { + cachedMessage = string.Format(formatProvider, format, args); + return cachedMessage; + } + } + + #endregion + + #region StringFormatFormattedMessage + + /// + /// Format string on demand. + /// + protected class StringFormatFormattedMessage + { + private volatile string cachedMessage; + + private readonly IFormatProvider FormatProvider; + private readonly string Message; + private readonly object[] Args; + + /// + /// Initializes a new instance of the class. + /// + /// The format provider. + /// The message. + /// The args. + public StringFormatFormattedMessage(IFormatProvider formatProvider, string message, params object[] args) + { + FormatProvider = formatProvider; + Message = message; + Args = args; + } + + /// + /// Runs on supplied arguemnts. + /// + /// string + public override string ToString() + { + if (cachedMessage == null && Message != null) + { + cachedMessage = string.Format(FormatProvider, Message, Args); + } + return cachedMessage; + } + } + + #endregion + + /// + /// Represents a method responsible for writing a message to the log system. + /// + protected delegate void WriteHandler(LogLevel level, object message, Exception exception); + + /// + /// Holds the method for writing a message to the log system. + /// + private readonly WriteHandler Write; + + /// + /// Creates a new logger instance using for + /// writing log events to the underlying log system. + /// + /// + protected AbstractLogger() + { + Write = GetWriteHandler(); + if (Write == null) + { + Write = new WriteHandler(WriteInternal); + } + } + + /// + /// Override this method to use a different method than + /// for writing log events to the underlying log system. + /// + /// + /// Usually you don't need to override thise method. The default implementation returns + /// null to indicate that the default handler should be + /// used. + /// + protected virtual WriteHandler GetWriteHandler() + { + return null; + } + + /// + /// Checks if this logger is enabled for the level. + /// + /// + /// Override this in your derived class to comply with the underlying logging system + /// + public abstract bool IsTraceEnabled { get; } + + /// + /// Checks if this logger is enabled for the level. + /// + /// + /// Override this in your derived class to comply with the underlying logging system + /// + public abstract bool IsDebugEnabled { get; } + + /// + /// Checks if this logger is enabled for the level. + /// + /// + /// Override this in your derived class to comply with the underlying logging system + /// + public abstract bool IsInfoEnabled { get; } + + /// + /// Checks if this logger is enabled for the level. + /// + /// + /// Override this in your derived class to comply with the underlying logging system + /// + public abstract bool IsWarnEnabled { get; } + + /// + /// Checks if this logger is enabled for the level. + /// + /// + /// Override this in your derived class to comply with the underlying logging system + /// + public abstract bool IsErrorEnabled { get; } + + /// + /// Checks if this logger is enabled for the level. + /// + /// + /// Override this in your derived class to comply with the underlying logging system + /// + public abstract bool IsFatalEnabled { get; } + + /// + /// Actually sends the message to the underlying log system. + /// + /// the level of this log event. + /// the message to log + /// the exception to log (may be null) + protected abstract void WriteInternal(LogLevel level, object message, Exception exception); + + #region Trace + + /// + /// Log a message object with the level. + /// + /// The message object to log. + public virtual void Trace(object message) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, message, null); + } + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + public virtual void Trace(object message, Exception exception) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, message, exception); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + public virtual void TraceFormat(IFormatProvider formatProvider, string format, params object[] args) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new StringFormatFormattedMessage(formatProvider, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + public virtual void TraceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new StringFormatFormattedMessage(formatProvider, format, args), exception); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + public virtual void TraceFormat(string format, params object[] args) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new StringFormatFormattedMessage(null, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + public virtual void TraceFormat(string format, Exception exception, params object[] args) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new StringFormatFormattedMessage(null, format, args), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Trace(FormatMessageCallback formatMessageCallback) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + public virtual void Trace(FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + public virtual void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsTraceEnabled) + Write(LogLevel.Trace, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); + } + + #endregion + + #region Debug + + /// + /// Log a message object with the level. + /// + /// The message object to log. + public virtual void Debug(object message) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, message, null); + } + + /// + /// Log a message object with the level including + /// the stack Debug of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack Debug. + public virtual void Debug(object message, Exception exception) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, message, exception); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + public virtual void DebugFormat(IFormatProvider formatProvider, string format, params object[] args) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new StringFormatFormattedMessage(formatProvider, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + public virtual void DebugFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new StringFormatFormattedMessage(formatProvider, format, args), exception); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + public virtual void DebugFormat(string format, params object[] args) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new StringFormatFormattedMessage(null, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + public virtual void DebugFormat(string format, Exception exception, params object[] args) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new StringFormatFormattedMessage(null, format, args), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Debug(FormatMessageCallback formatMessageCallback) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Debug. + public virtual void Debug(FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Debug. + public virtual void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsDebugEnabled) + Write(LogLevel.Debug, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); + } + + #endregion + + #region Info + + /// + /// Log a message object with the level. + /// + /// The message object to log. + public virtual void Info(object message) + { + if (IsInfoEnabled) + Write(LogLevel.Info, message, null); + } + + /// + /// Log a message object with the level including + /// the stack Info of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack Info. + public virtual void Info(object message, Exception exception) + { + if (IsInfoEnabled) + Write(LogLevel.Info, message, exception); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + public virtual void InfoFormat(IFormatProvider formatProvider, string format, params object[] args) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new StringFormatFormattedMessage(formatProvider, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + public virtual void InfoFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new StringFormatFormattedMessage(formatProvider, format, args), exception); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + public virtual void InfoFormat(string format, params object[] args) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new StringFormatFormattedMessage(null, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + public virtual void InfoFormat(string format, Exception exception, params object[] args) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new StringFormatFormattedMessage(null, format, args), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Info(FormatMessageCallback formatMessageCallback) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Info. + public virtual void Info(FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Info. + public virtual void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsInfoEnabled) + Write(LogLevel.Info, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); + } + + #endregion + + #region Warn + + /// + /// Log a message object with the level. + /// + /// The message object to log. + public virtual void Warn(object message) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, message, null); + } + + /// + /// Log a message object with the level including + /// the stack Warn of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack Warn. + public virtual void Warn(object message, Exception exception) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, message, exception); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Warnrmation. + /// The format of the message object to log. + /// + public virtual void WarnFormat(IFormatProvider formatProvider, string format, params object[] args) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new StringFormatFormattedMessage(formatProvider, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Warnrmation. + /// The format of the message object to log. + /// The exception to log. + /// + public virtual void WarnFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new StringFormatFormattedMessage(formatProvider, format, args), exception); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + public virtual void WarnFormat(string format, params object[] args) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new StringFormatFormattedMessage(null, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + public virtual void WarnFormat(string format, Exception exception, params object[] args) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new StringFormatFormattedMessage(null, format, args), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Warn(FormatMessageCallback formatMessageCallback) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Warn. + public virtual void Warn(FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Warn. + public virtual void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsWarnEnabled) + Write(LogLevel.Warn, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); + } + + #endregion + + #region Error + + /// + /// Log a message object with the level. + /// + /// The message object to log. + public virtual void Error(object message) + { + if (IsErrorEnabled) + Write(LogLevel.Error, message, null); + } + + /// + /// Log a message object with the level including + /// the stack Error of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack Error. + public virtual void Error(object message, Exception exception) + { + if (IsErrorEnabled) + Write(LogLevel.Error, message, exception); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Errorrmation. + /// The format of the message object to log. + /// + public virtual void ErrorFormat(IFormatProvider formatProvider, string format, params object[] args) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new StringFormatFormattedMessage(formatProvider, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Errorrmation. + /// The format of the message object to log. + /// The exception to log. + /// + public virtual void ErrorFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new StringFormatFormattedMessage(formatProvider, format, args), exception); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + public virtual void ErrorFormat(string format, params object[] args) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new StringFormatFormattedMessage(null, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + public virtual void ErrorFormat(string format, Exception exception, params object[] args) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new StringFormatFormattedMessage(null, format, args), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Error(FormatMessageCallback formatMessageCallback) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Error. + public virtual void Error(FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Error. + public virtual void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsErrorEnabled) + Write(LogLevel.Error, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); + } + + #endregion + + #region Fatal + + /// + /// Log a message object with the level. + /// + /// The message object to log. + public virtual void Fatal(object message) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, message, null); + } + + /// + /// Log a message object with the level including + /// the stack Fatal of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack Fatal. + public virtual void Fatal(object message, Exception exception) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, message, exception); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Fatalrmation. + /// The format of the message object to log. + /// + public virtual void FatalFormat(IFormatProvider formatProvider, string format, params object[] args) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new StringFormatFormattedMessage(formatProvider, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting Fatalrmation. + /// The format of the message object to log. + /// The exception to log. + /// + public virtual void FatalFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new StringFormatFormattedMessage(formatProvider, format, args), exception); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + public virtual void FatalFormat(string format, params object[] args) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new StringFormatFormattedMessage(null, format, args), null); + } + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + public virtual void FatalFormat(string format, Exception exception, params object[] args) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new StringFormatFormattedMessage(null, format, args), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Fatal(FormatMessageCallback formatMessageCallback) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + public virtual void Fatal(FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public virtual void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); + } + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + public virtual void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + if (IsFatalEnabled) + Write(LogLevel.Fatal, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/NamespaceDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/NamespaceDoc.cs new file mode 100644 index 0000000..8eef63d --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/NamespaceDoc.cs @@ -0,0 +1,31 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 + +namespace Common.Logging.Factory +{ + /// + /// This namespace contains convenience base classes for implementing your own s. + /// + [CoverageExclude] + internal static class NamespaceDoc + { + // serves as namespace summary for NDoc3 (http://ndoc3.sourceforge.net) + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/FormatMessageHandler.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/FormatMessageHandler.cs new file mode 100644 index 0000000..5f6babc --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/FormatMessageHandler.cs @@ -0,0 +1,32 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 + +namespace Common.Logging +{ + /// + /// The type of method that is passed into e.g. + /// and allows the callback method to "submit" it's message to the underlying output system. + /// + ///the format argument as in + ///the argument list as in + /// + /// Erich Eichinger + public delegate string FormatMessageHandler(string format, params object[] args); +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/IConfigurationReader.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/IConfigurationReader.cs new file mode 100644 index 0000000..2822a08 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/IConfigurationReader.cs @@ -0,0 +1,49 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Configuration; + +namespace Common.Logging +{ + + /// + /// Interface for basic operations to read .NET application configuration information. + /// + /// Provides a simple abstraction to handle BCL API differences between .NET 1.x and 2.0. Also + /// useful for testing scenarios. + /// Mark Pollack + public interface IConfigurationReader + { + /// + /// Parses the configuration section and returns the resulting object. + /// + /// + ///

+ /// Primary purpose of this method is to allow us to parse and + /// load configuration sections using the same API regardless + /// of the .NET framework version. + ///

+ ///
+ /// Name of the configuration section. + /// Object created by a corresponding . + /// + object GetSection(string sectionName); + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILog.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILog.cs new file mode 100644 index 0000000..6869265 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILog.cs @@ -0,0 +1,649 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 FormatMessageCallback = System.Action; + +namespace Common.Logging +{ + /// + /// A simple logging interface abstracting logging APIs. + /// + /// + /// + /// Implementations should defer calling a message's until the message really needs + /// to be logged to avoid performance penalties. + /// + /// + /// Each log method offers to pass in a instead of the actual message. + /// Using this style has the advantage to defer possibly expensive message argument evaluation and formatting (and formatting arguments!) until the message gets + /// actually logged. If the message is not logged at all (e.g. due to settings), + /// you won't have to pay the peformance penalty of creating the message. + /// + /// + /// + /// The example below demonstrates using callback style for creating the message, where the call to the + /// and the underlying only happens, if level is enabled: + /// + /// Log.Debug( m=>m("result is {0}", random.NextDouble()) ); + /// Log.Debug(delegate(m) { m("result is {0}", random.NextDouble()); }); + /// + /// + /// + /// Mark Pollack + /// Bruno Baia + /// Erich Eichinger + public interface ILog + { + /// + /// Log a message object with the level. + /// + /// The message object to log. + void Trace(object message); + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + void Trace(object message, Exception exception); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + void TraceFormat(string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + void TraceFormat(string format, Exception exception, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + void TraceFormat(IFormatProvider formatProvider, string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + void TraceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + void Trace(FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Trace(FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message object with the level. + /// + /// The message object to log. + void Debug( object message ); + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + void Debug( object message, Exception exception ); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + void DebugFormat(string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + void DebugFormat(string format, Exception exception, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + void DebugFormat(IFormatProvider formatProvider, string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + void DebugFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + void Debug(FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Debug(FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Debug. + void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message object with the level. + /// + /// The message object to log. + void Info(object message); + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + void Info(object message, Exception exception); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + void InfoFormat(string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + void InfoFormat(string format, Exception exception, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + void InfoFormat(IFormatProvider formatProvider, string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + void InfoFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + void Info(FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Info(FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Info. + void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message object with the level. + /// + /// The message object to log. + void Warn(object message); + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + void Warn(object message, Exception exception); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + void WarnFormat(string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + void WarnFormat(string format, Exception exception, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + void WarnFormat(IFormatProvider formatProvider, string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + void WarnFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + void Warn(FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Warn(FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Warn. + void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message object with the level. + /// + /// The message object to log. + void Error( object message ); + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + void Error( object message, Exception exception ); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + void ErrorFormat(string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + void ErrorFormat(string format, Exception exception, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + void ErrorFormat(IFormatProvider formatProvider, string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + void ErrorFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + void Error(FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Error(FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Error. + void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message object with the level. + /// + /// The message object to log. + void Fatal( object message ); + + /// + /// Log a message object with the level including + /// the stack trace of the passed + /// as a parameter. + /// + /// The message object to log. + /// The exception to log, including its stack trace. + void Fatal( object message, Exception exception ); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// the list of format arguments + void FatalFormat(string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of format arguments + void FatalFormat(string format, Exception exception, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// + void FatalFormat(IFormatProvider formatProvider, string format, params object[] args); + + /// + /// Log a message with the level. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// + void FatalFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + void Fatal(FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + void Fatal(FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); + + /// + /// Log a message with the level using a callback to obtain the message + /// + /// + /// Using this method avoids the cost of creating a message and evaluating message arguments + /// that probably won't be logged due to loglevel settings. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); + + /// + /// Checks if this logger is enabled for the level. + /// + bool IsTraceEnabled + { + get; + } + + /// + /// Checks if this logger is enabled for the level. + /// + bool IsDebugEnabled + { + get; + } + + /// + /// Checks if this logger is enabled for the level. + /// + bool IsErrorEnabled + { + get; + } + + /// + /// Checks if this logger is enabled for the level. + /// + bool IsFatalEnabled + { + get; + } + + /// + /// Checks if this logger is enabled for the level. + /// + bool IsInfoEnabled + { + get; + } + + /// + /// Checks if this logger is enabled for the level. + /// + bool IsWarnEnabled + { + get; + } + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILoggerFactoryAdapter.cs new file mode 100644 index 0000000..524bc52 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILoggerFactoryAdapter.cs @@ -0,0 +1,49 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 Common.Logging +{ + /// + /// LoggerFactoryAdapter interface is used internally by LogManager + /// Only developers wishing to write new Common.Logging adapters need to + /// worry about this interface. + /// + /// Gilles Bayon + public interface ILoggerFactoryAdapter + { + + /// + /// Get a ILog instance by type. + /// + /// The type to use for the logger + /// + ILog GetLogger( Type type ); + + /// + /// Get a ILog instance by name. + /// + /// The name of the logger + /// + ILog GetLogger( string name ); + + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogLevel.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogLevel.cs new file mode 100644 index 0000000..f1ad189 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogLevel.cs @@ -0,0 +1,62 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 + +namespace Common.Logging +{ + /// + /// The 7 possible logging levels + /// + /// Gilles Bayon + public enum LogLevel + { + /// + /// All logging levels + /// + All = 0, + /// + /// A trace logging level + /// + Trace = 1, + /// + /// A debug logging level + /// + Debug = 2, + /// + /// A info logging level + /// + Info = 3, + /// + /// A warn logging level + /// + Warn = 4, + /// + /// An error logging level + /// + Error = 5, + /// + /// A fatal logging level + /// + Fatal = 6, + /// + /// Do not log anything. + /// + Off = 7, + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogManager.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogManager.cs new file mode 100644 index 0000000..4ba8d98 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogManager.cs @@ -0,0 +1,333 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Configuration; +using System.Diagnostics; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Security; +using System.Security.Permissions; +using Common.Logging.Simple; +using Common.Logging.Configuration; + +namespace Common.Logging +{ + /// + /// Use the LogManager's or + /// methods to obtain instances for logging. + /// + /// + /// For configuring the underlying log system using application configuration, see the example + /// at . + /// For configuring programmatically, see the example section below. + /// + /// + /// The example below shows the typical use of LogManager to obtain a reference to a logger + /// and log an exception: + /// + /// + /// ILog log = LogManager.GetLogger(this.GetType()); + /// ... + /// try + /// { + /// /* .... */ + /// } + /// catch(Exception ex) + /// { + /// log.ErrorFormat("Hi {0}", ex, "dude"); + /// } + /// + /// + /// The example below shows programmatic configuration of the underlying log system: + /// + /// + /// // create properties + /// NameValueCollection properties = new NameValueCollection(); + /// properties["showDateTime"] = "true"; + /// + /// // set Adapter + /// Common.Logging.LogManager.Adapter = new + /// Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(properties); + /// + /// + /// + /// + /// + /// + /// + /// Gilles Bayon + public static class LogManager + { + /// + /// The name of the default configuration section to read settings from. + /// + /// + /// You can always change the source of your configuration settings by setting another instance + /// on . + /// + public static readonly string COMMON_LOGGING_SECTION = "Settings.bundle/Common.Logging.plist"; + + private static IConfigurationReader _configurationReader; + private static ILoggerFactoryAdapter _adapter; + private static readonly object _loadLock = new object(); + + /// + /// Performs static 1-time init of LogManager by calling + /// + static LogManager() + { + Reset(); + } + + /// + /// Reset the infrastructure to its default settings. This means, that configuration settings + /// will be re-read from section <common/logging> of your app.config. + /// + /// + /// This is mainly used for unit testing, you wouldn't normally use this in your applications.
+ /// Note: instances already handed out from this LogManager are not(!) affected. + /// Resetting LogManager only affects new instances being handed out. + ///
+ public static void Reset() + { + Reset(new MonoTouchConfigurationReader()); + } + + /// + /// Reset the infrastructure to its default settings. This means, that configuration settings + /// will be re-read from section <common/logging> of your app.config. + /// + /// + /// This is mainly used for unit testing, you wouldn't normally use this in your applications.
+ /// Note: instances already handed out from this LogManager are not(!) affected. + /// Resetting LogManager only affects new instances being handed out. + ///
+ /// + /// the instance to obtain settings for + /// re-initializing the LogManager. + /// + public static void Reset(IConfigurationReader reader) + { + lock (_loadLock) + { + if (reader == null) + { + throw new ArgumentNullException("reader"); + } + _configurationReader = reader; + _adapter = null; + } + } + + /// + /// Gets the configuration reader used to initialize the LogManager. + /// + /// Primarily used for testing purposes but maybe useful to obtain configuration + /// information from some place other than the .NET application configuration file. + /// The configuration reader. + public static IConfigurationReader ConfigurationReader + { + get + { + return _configurationReader; + } + } + + /// + /// Gets or sets the adapter. + /// + /// The adapter. + public static ILoggerFactoryAdapter Adapter + { + get + { + if (_adapter == null) + { + lock (_loadLock) + { + if (_adapter == null) + { + _adapter = BuildLoggerFactoryAdapter(); + } + } + } + return _adapter; + } + set + { + if (value == null) + { + throw new ArgumentNullException("Adapter"); + } + + lock (_loadLock) + { + _adapter = value; + } + } + } + + /// + /// Gets the logger by calling + /// on the currently configured using the type of the calling class. + /// + /// + /// This method needs to inspect the in order to determine the calling + /// class. This of course comes with a performance penalty, thus you shouldn't call it too + /// often in your application. + /// + /// + /// the logger instance obtained from the current + [MethodImpl(MethodImplOptions.NoInlining)] + public static ILog GetCurrentClassLogger() + { + StackFrame frame = new StackFrame(1, false); + ILoggerFactoryAdapter adapter = Adapter; + MethodBase method = frame.GetMethod(); + Type declaringType = method.DeclaringType; + return adapter.GetLogger(declaringType); + } + + /// + /// Gets the logger by calling + /// on the currently configured using the specified type. + /// + /// the logger instance obtained from the current + public static ILog GetLogger() + { + return Adapter.GetLogger(typeof(T)); + } + + /// + /// Gets the logger by calling + /// on the currently configured using the specified type. + /// + /// The type. + /// the logger instance obtained from the current + public static ILog GetLogger(Type type) + { + return Adapter.GetLogger(type); + } + + + /// + /// Gets the logger by calling + /// on the currently configured using the specified name. + /// + /// The name. + /// the logger instance obtained from the current + public static ILog GetLogger(string name) + { + return Adapter.GetLogger(name); + } + + + /// + /// Builds the logger factory adapter. + /// + /// a factory adapter instance. Is never null. + private static ILoggerFactoryAdapter BuildLoggerFactoryAdapter() + { + object sectionResult = null; + + ArgUtils.Guard(delegate + { + sectionResult = ConfigurationReader.GetSection(COMMON_LOGGING_SECTION); + } + , "Failed obtaining configuration for Common.Logging from configuration section 'common/logging'."); + + // configuration reader returned + if (sectionResult == null) + { + string message = (ConfigurationReader.GetType() == typeof(MonoTouchConfigurationReader)) + ? string.Format("no configuration plist <{0}> found - suppressing logging output", COMMON_LOGGING_SECTION) + : string.Format("Custom ConfigurationReader '{0}' returned - suppressing logging output", ConfigurationReader.GetType().FullName); + Console.Error.WriteLine(message); + ILoggerFactoryAdapter defaultFactory = new NoOpLoggerFactoryAdapter(); + return defaultFactory; + } + + // ready to use ILoggerFactoryAdapter? + if (sectionResult is ILoggerFactoryAdapter) + { + Console.Error.WriteLine(string.Format("Using ILoggerFactoryAdapter returned from custom ConfigurationReader '{0}'", ConfigurationReader.GetType().FullName)); + return (ILoggerFactoryAdapter)sectionResult; + } + + // ensure what's left is a LogSetting instance + ArgUtils.Guard(delegate + { + ArgUtils.AssertIsAssignable("sectionResult", sectionResult.GetType()); + } + , "ConfigurationReader {0} returned unknown settings instance of type {1}" + , ConfigurationReader.GetType().FullName, sectionResult.GetType().FullName); + + ILoggerFactoryAdapter adapter = null; + ArgUtils.Guard(delegate + { + adapter = BuildLoggerFactoryAdapterFromLogSettings((LogSetting)sectionResult); + } + , "Failed creating LoggerFactoryAdapter from settings"); + + return adapter; + } + + /// + /// Builds a instance from the given + /// using . + /// + /// + /// the instance. Is never null + private static ILoggerFactoryAdapter BuildLoggerFactoryAdapterFromLogSettings(LogSetting setting) + { + ArgUtils.AssertNotNull("setting", setting); + // already ensured by LogSetting + // AssertArgIsAssignable("setting.FactoryAdapterType", setting.FactoryAdapterType + // , "Specified FactoryAdapter does not implement {0}. Check implementation of class {1}" + // , typeof(ILoggerFactoryAdapter).FullName + // , setting.FactoryAdapterType.AssemblyQualifiedName); + + ILoggerFactoryAdapter adapter = null; + + ArgUtils.Guard(delegate + { + if (setting.Properties != null + && setting.Properties.Count > 0) + { + object[] args = { setting.Properties }; + + adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType, args); + } + else + { + adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType); + } + } + , "Unable to create instance of type {0}. Possible explanation is lack of zero arg and single arg NameValueCollection constructors" + , setting.FactoryAdapterType.FullName + ); + + // make sure + ArgUtils.AssertNotNull("adapter", adapter, "Activator.CreateInstance() returned "); + return adapter; + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/MonoNet/CollectionsUtil.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/MonoNet/CollectionsUtil.cs new file mode 100644 index 0000000..c570861 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/MonoNet/CollectionsUtil.cs @@ -0,0 +1,64 @@ +// +// System.Collections.Specialized.CollectionsUtil.cs +// +// Author: +// Lawrence Pit (loz@cable.a2000.nl) +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System.Collections; + +namespace System.Collections.Specialized { + +#if !NET_2_1 + public +#else + internal +#endif + class CollectionsUtil { + + public CollectionsUtil () {} + + public static Hashtable CreateCaseInsensitiveHashtable () + { + return new Hashtable (CaseInsensitiveHashCodeProvider.Default, + CaseInsensitiveComparer.Default); + } + + + public static Hashtable CreateCaseInsensitiveHashtable (IDictionary d) { + return new Hashtable (d, CaseInsensitiveHashCodeProvider.Default, + CaseInsensitiveComparer.Default); + } + + public static Hashtable CreateCaseInsensitiveHashtable (int capacity) { + return new Hashtable (capacity, CaseInsensitiveHashCodeProvider.Default, + CaseInsensitiveComparer.Default); + } + + + public static SortedList CreateCaseInsensitiveSortedList () { + return new SortedList (CaseInsensitiveComparer.Default); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/NamespaceDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/NamespaceDoc.cs new file mode 100644 index 0000000..8548947 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/NamespaceDoc.cs @@ -0,0 +1,31 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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 + +namespace Common.Logging +{ + /// + /// This namespace contains all core classes making up the Common.Logging framework. + /// + [CoverageExclude] + internal static class NamespaceDoc + { + // serves as namespace summary for NDoc3 (http://ndoc3.sourceforge.net) + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLogger.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLogger.cs new file mode 100644 index 0000000..fb541ed --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLogger.cs @@ -0,0 +1,263 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Globalization; +using System.Text; +using Common.Logging.Factory; + +namespace Common.Logging.Simple +{ + /// + /// Abstract class providing a standard implementation of simple loggers. + /// + /// Erich Eichinger + [Serializable] + public abstract class AbstractSimpleLogger : AbstractLogger + { + private readonly string _name; + private readonly bool _showLevel; + private readonly bool _showDateTime; + private readonly bool _showLogName; + private LogLevel _currentLogLevel; + private readonly string _dateTimeFormat; + private readonly bool _hasDateTimeFormat; + + #region Properties + + /// + /// The name of the logger. + /// + [CoverageExclude] + public string Name + { + get { return _name; } + } + + /// + /// Include the current log level in the log message. + /// + [CoverageExclude] + public bool ShowLevel + { + get { return _showLevel; } + } + + /// + /// Include the current time in the log message. + /// + [CoverageExclude] + public bool ShowDateTime + { + get { return _showDateTime; } + } + + /// + /// Include the instance name in the log message. + /// + [CoverageExclude] + public bool ShowLogName + { + get { return _showLogName; } + } + + /// + /// The current logging threshold. Messages recieved that are beneath this threshold will not be logged. + /// + [CoverageExclude] + public LogLevel CurrentLogLevel + { + get { return _currentLogLevel; } + set { _currentLogLevel = value; } + } + + /// + /// The date and time format to use in the log message. + /// + [CoverageExclude] + public string DateTimeFormat + { + get { return _dateTimeFormat; } + } + + /// + /// Determines Whether is set. + /// + [CoverageExclude] + public bool HasDateTimeFormat + { + get { return _hasDateTimeFormat; } + } + + + #endregion + + /// + /// Creates and initializes a the simple logger. + /// + /// The name, usually type name of the calling class, of the logger. + /// The current logging threshold. Messages recieved that are beneath this threshold will not be logged. + /// Include level in the log message. + /// Include the current time in the log message. + /// Include the instance name in the log message. + /// The date and time format to use in the log message. + public AbstractSimpleLogger(string logName, LogLevel logLevel, bool showlevel + , bool showDateTime, bool showLogName, string dateTimeFormat) + { + _name = logName; + _currentLogLevel = logLevel; + _showLevel = showlevel; + _showDateTime = showDateTime; + _showLogName = showLogName; + _dateTimeFormat = dateTimeFormat; + _hasDateTimeFormat = (!string.IsNullOrEmpty(_dateTimeFormat)); + } + + /// + /// Appends the formatted message to the specified . + /// + /// the that receíves the formatted message. + /// + /// + /// + protected virtual void FormatOutput(StringBuilder stringBuilder, LogLevel level, object message, Exception e) + { + if (stringBuilder == null) + { + throw new ArgumentNullException("stringBuilder"); + } + + // Append date-time if so configured + if (_showDateTime) + { + if (_hasDateTimeFormat) + { + stringBuilder.Append(DateTime.Now.ToString(_dateTimeFormat, CultureInfo.InvariantCulture)); + } + else + { + stringBuilder.Append(DateTime.Now); + } + + stringBuilder.Append(" "); + } + + if (_showLevel) + { + // Append a readable representation of the log level + stringBuilder.Append(("[" + level.ToString().ToUpper() + "]").PadRight(8)); + } + + // Append the name of the log instance if so configured + if (_showLogName) + { + stringBuilder.Append(_name).Append(" - "); + } + + // Append the message + stringBuilder.Append(message); + + // Append stack trace if not null + if (e != null) + { + stringBuilder.Append(Environment.NewLine).Append(e.ToString()); + } + } + + /// + /// Determines if the given log level is currently enabled. + /// + /// + /// + protected virtual bool IsLevelEnabled(LogLevel level) + { + int iLevel = (int)level; + int iCurrentLogLevel = (int)_currentLogLevel; + + // return iLevel.CompareTo(iCurrentLogLevel); better ??? + return (iLevel >= iCurrentLogLevel); + } + + #region ILog Members + + /// + /// Returns if the current is greater than or + /// equal to . If it is, all messages will be sent to . + /// + public override bool IsTraceEnabled + { + get { return IsLevelEnabled(LogLevel.Trace); } + } + + /// + /// Returns if the current is greater than or + /// equal to . If it is, all messages will be sent to . + /// + public override bool IsDebugEnabled + { + get { return IsLevelEnabled(LogLevel.Debug); } + } + + /// + /// Returns if the current is greater than or + /// equal to . If it is, only messages with a of + /// , , , and + /// will be sent to . + /// + public override bool IsInfoEnabled + { + get { return IsLevelEnabled(LogLevel.Info); } + } + + + /// + /// Returns if the current is greater than or + /// equal to . If it is, only messages with a of + /// , , and + /// will be sent to . + /// + public override bool IsWarnEnabled + { + get { return IsLevelEnabled(LogLevel.Warn); } + } + + /// + /// Returns if the current is greater than or + /// equal to . If it is, only messages with a of + /// and will be sent to . + /// + public override bool IsErrorEnabled + { + get { return IsLevelEnabled(LogLevel.Error); } + } + + /// + /// Returns if the current is greater than or + /// equal to . If it is, only messages with a of + /// will be sent to . + /// + public override bool IsFatalEnabled + { + get { return IsLevelEnabled(LogLevel.Fatal); } + } + + #endregion + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs new file mode 100644 index 0000000..f2a36f9 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs @@ -0,0 +1,168 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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.Collections.Specialized; +using Common.Logging.Factory; + +namespace Common.Logging.Simple +{ + /// + /// Base factory implementation for creating simple instances. + /// + /// Default settings are LogLevel.All, showDateTime = true, showLogName = true, and no DateTimeFormat. + /// The keys in the NameValueCollection to configure this adapter are the following + /// + /// level + /// showDateTime + /// showLogName + /// dateTimeFormat + /// + /// + /// Here is an example how to implement your own logging adapter: + /// + /// public class ConsoleOutLogger : AbstractSimpleLogger + /// { + /// public ConsoleOutLogger(string logName, LogLevel logLevel, bool showLevel, bool showDateTime, + /// bool showLogName, string dateTimeFormat) + /// : base(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat) + /// { + /// } + /// + /// protected override void WriteInternal(LogLevel level, object message, Exception e) + /// { + /// // Use a StringBuilder for better performance + /// StringBuilder sb = new StringBuilder(); + /// FormatOutput(sb, level, message, e); + /// + /// // Print to the appropriate destination + /// Console.Out.WriteLine(sb.ToString()); + /// } + /// } + /// + /// public class ConsoleOutLoggerFactoryAdapter : AbstractSimpleLoggerFactoryAdapter + /// { + /// public ConsoleOutLoggerFactoryAdapter(NameValueCollection properties) + /// : base(properties) + /// { } + /// + /// protected override ILog CreateLogger(string name, LogLevel level, bool showLevel, bool + /// showDateTime, bool showLogName, string dateTimeFormat) + /// { + /// ILog log = new ConsoleOutLogger(name, level, showLevel, showDateTime, showLogName, + /// dateTimeFormat); + /// return log; + /// } + /// } + /// + /// + /// + /// + /// + /// Gilles Bayon + /// Mark Pollack + /// Erich Eichinger + public abstract class AbstractSimpleLoggerFactoryAdapter : AbstractCachingLoggerFactoryAdapter + { + private LogLevel _level; + private bool _showLevel; + private bool _showDateTime; + private bool _showLogName; + private string _dateTimeFormat; + + /// + /// The default to use when creating new instances. + /// + [CoverageExclude] + public LogLevel Level + { + get { return _level; } + set { _level = value; } + } + + /// + /// The default setting to use when creating new instances. + /// + [CoverageExclude] + public bool ShowLevel + { + get { return _showLevel; } + set { _showLevel = value; } + } + + /// + /// The default setting to use when creating new instances. + /// + [CoverageExclude] + public bool ShowDateTime + { + get { return _showDateTime; } + set { _showDateTime = value; } + } + + /// + /// The default setting to use when creating new instances. + /// + [CoverageExclude] + public bool ShowLogName + { + get { return _showLogName; } + set { _showLogName = value; } + } + + /// + /// The default setting to use when creating new instances. + /// + [CoverageExclude] + public string DateTimeFormat + { + get { return _dateTimeFormat; } + set { _dateTimeFormat = value; } + } + + /// + /// Initializes a new instance of the class with + /// default settings for the loggers created by this factory. + /// + protected AbstractSimpleLoggerFactoryAdapter(LogLevel level, bool showDateTime, bool showLogName, bool showLevel, string dateTimeFormat) + :base(true) + { + _level = level; + _showDateTime = showDateTime; + _showLogName = showLogName; + _showLevel = showLevel; + _dateTimeFormat = dateTimeFormat ?? string.Empty; + } + + /// + /// Create the specified logger instance + /// + protected override ILog CreateLogger(string name) + { + return CreateLogger(name, _level, _showLevel, _showDateTime, _showLogName, _dateTimeFormat); + } + + /// + /// Derived factories need to implement this method to create the + /// actual logger instance. + /// + /// a new logger instance. Must never be null! + protected abstract ILog CreateLogger(string name, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat); + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLogger.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLogger.cs new file mode 100644 index 0000000..735e35f --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLogger.cs @@ -0,0 +1,64 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 Common.Logging.Simple +{ + /// + /// Sends log messages to . + /// + /// Gilles Bayon + [Serializable] + public class ConsoleOutLogger : AbstractSimpleLogger + { + /// + /// Creates and initializes a logger that writes messages to . + /// + /// The name, usually type name of the calling class, of the logger. + /// The current logging threshold. Messages recieved that are beneath this threshold will not be logged. + /// Include the current log level in the log message. + /// Include the current time in the log message. + /// Include the instance name in the log message. + /// The date and time format to use in the log message. + public ConsoleOutLogger(string logName, LogLevel logLevel, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) + : base(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat) + { + } + + /// + /// Do the actual logging by constructing the log message using a then + /// sending the output to . + /// + /// The of the message. + /// The log message. + /// An optional associated with the message. + protected override void WriteInternal(LogLevel level, object message, Exception e) + { + // Use a StringBuilder for better performance + StringBuilder sb = new StringBuilder(); + FormatOutput(sb, level, message, e); + + // Print to the appropriate destination + Console.Out.WriteLine(sb.ToString()); + } + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs new file mode 100644 index 0000000..02b5455 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs @@ -0,0 +1,81 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 Common.Logging.Simple +{ + /// + /// Factory for creating instances that write data to . + /// + /// + /// + /// Below is an example how to configure this adapter: + /// + /// <configuration> + /// + /// <configSections> + /// <sectionGroup name="common"> + /// <section name="logging" + /// type="Common.Logging.ConfigurationSectionHandler, Common.Logging" + /// requirePermission="false" /> + /// </sectionGroup> + /// </configSections> + /// + /// <common> + /// <logging> + /// <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging"> + /// <arg key="level" value="ALL" /> + /// </factoryAdapter> + /// </logging> + /// </common> + /// + /// </configuration> + /// + /// + /// + /// + /// + /// + /// Gilles Bayon + /// Mark Pollack + /// Erich Eichinger + public class ConsoleOutLoggerFactoryAdapter : AbstractSimpleLoggerFactoryAdapter + { + + /// + /// Initializes a new instance of the class with + /// default settings for the loggers created by this factory. + /// + public ConsoleOutLoggerFactoryAdapter(LogLevel level, bool showDateTime, bool showLogName, bool showLevel, string dateTimeFormat) + : base(level, showDateTime, showLogName, showLevel, dateTimeFormat) + { } + + /// + /// Creates a new instance. + /// + protected override ILog CreateLogger(string name, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) + { + ILog log = new ConsoleOutLogger(name, level, showLevel, showDateTime, showLogName, dateTimeFormat); + return log; + } + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NamespaceDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NamespaceDoc.cs new file mode 100644 index 0000000..99ff197 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NamespaceDoc.cs @@ -0,0 +1,31 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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 + +namespace Common.Logging.Simple +{ + /// + /// This namespace contains all core classes making up the Common.Logging framework. + /// + [CoverageExclude] + internal static class NamespaceDoc + { + // serves as namespace summary for NDoc3 (http://ndoc3.sourceforge.net) + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLogger.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLogger.cs new file mode 100644 index 0000000..3d5f287 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLogger.cs @@ -0,0 +1,731 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 FormatMessageCallback = System.Action; + +namespace Common.Logging.Simple +{ + /// + /// Silently ignores all log messages. + /// + /// Gilles Bayon + /// Erich Eichinger + [Serializable] + [CoverageExclude] + public sealed class NoOpLogger : ILog + { + #region IsXXXEnabled + + /// + /// Always returns . + /// + public bool IsTraceEnabled + { + get { return false; } + } + + /// + /// Always returns . + /// + public bool IsDebugEnabled + { + get { return false; } + } + + /// + /// Always returns . + /// + public bool IsInfoEnabled + { + get { return false; } + } + + /// + /// Always returns . + /// + public bool IsWarnEnabled + { + get { return false; } + } + + /// + /// Always returns . + /// + public bool IsErrorEnabled + { + get { return false; } + + } + + /// + /// Always returns . + /// + public bool IsFatalEnabled + { + get { return false; } + } + + #endregion + + #region Trace + + /// + /// Ignores message. + /// + /// + public void Trace(object message) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// + /// + public void Trace(object message, Exception e) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// + public void TraceFormat(string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void TraceFormat(string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// the list of message format arguments + public void TraceFormat(IFormatProvider formatProvider, string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void TraceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + public void Trace(FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + public void Trace(FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack trace. + public void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + #endregion + + #region Debug + + /// + /// Ignores message. + /// + /// + public void Debug(object message) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// + /// + public void Debug(object message, Exception e) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// + public void DebugFormat(string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void DebugFormat(string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// the list of message format arguments + public void DebugFormat(IFormatProvider formatProvider, string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void DebugFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + public void Debug(FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Debug. + public void Debug(FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Debug. + public void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + #endregion + + #region Info + + /// + /// Ignores message. + /// + /// + public void Info(object message) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// + /// + public void Info(object message, Exception e) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// + public void InfoFormat(string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void InfoFormat(string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// the list of message format arguments + public void InfoFormat(IFormatProvider formatProvider, string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void InfoFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + public void Info(FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Info. + public void Info(FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Info. + public void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + #endregion + + #region Warn + + /// + /// Ignores message. + /// + /// + public void Warn(object message) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// + /// + public void Warn(object message, Exception e) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// + public void WarnFormat(string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void WarnFormat(string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Warnrmation. + /// The format of the message object to log. + /// the list of message format arguments + public void WarnFormat(IFormatProvider formatProvider, string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Warnrmation. + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void WarnFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + public void Warn(FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Warn. + public void Warn(FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Warn. + public void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + #endregion + + #region Error + + /// + /// Ignores message. + /// + /// + public void Error(object message) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// + /// + public void Error(object message, Exception e) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// + public void ErrorFormat(string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void ErrorFormat(string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Errorrmation. + /// The format of the message object to log. + /// the list of message format arguments + public void ErrorFormat(IFormatProvider formatProvider, string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Errorrmation. + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void ErrorFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + public void Error(FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Error. + public void Error(FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Error. + public void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + #endregion + + #region Fatal + + /// + /// Ignores message. + /// + /// + public void Fatal(object message) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// + /// + public void Fatal(object message, Exception e) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// + public void FatalFormat(string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void FatalFormat(string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Fatalrmation. + /// The format of the message object to log. + /// the list of message format arguments + public void FatalFormat(IFormatProvider formatProvider, string format, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting Fatalrmation. + /// The format of the message object to log. + /// The exception to log. + /// the list of message format arguments + public void FatalFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + public void Fatal(FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + public void Fatal(FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + public void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) + { + // NOP - no operation + } + + /// + /// Ignores message. + /// + /// An that supplies culture-specific formatting information. + /// A callback used by the logger to obtain the message if log level is matched + /// The exception to log, including its stack Fatal. + public void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) + { + // NOP - no operation + } + + #endregion + + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLoggerFactoryAdapter.cs new file mode 100644 index 0000000..d1aa14b --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLoggerFactoryAdapter.cs @@ -0,0 +1,102 @@ +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 Common.Logging.Simple +{ + /// + /// Factory for creating instances that silently ignores + /// logging requests. + /// + /// + /// This logger adapter is the default used by Common.Logging if unconfigured. Using this logger adapter is the most efficient + /// way to suppress any logging output. + /// + /// Below is an example how to configure this adapter: + /// + /// <configuration> + /// + /// <configSections> + /// <sectionGroup name="common"> + /// <section name="logging" + /// type="Common.Logging.ConfigurationSectionHandler, Common.Logging" + /// requirePermission="false" /> + /// </sectionGroup> + /// </configSections> + /// + /// <common> + /// <logging> + /// <factoryAdapter type="Common.Logging.Simple.NoOpLoggerFactoryAdapter, Common.Logging"> + /// <arg key="level" value="ALL" /> + /// </factoryAdapter> + /// </logging> + /// </common> + /// + /// </configuration> + /// + /// + /// + /// + /// + /// Gilles Bayon + public sealed class NoOpLoggerFactoryAdapter : ILoggerFactoryAdapter + { + private static readonly ILog s_nopLogger = new NoOpLogger(); + + /// + /// Constructor + /// + public NoOpLoggerFactoryAdapter() + { } + + /// + /// Constructor + /// + public NoOpLoggerFactoryAdapter(NameValueCollection properties) + { } + + #region ILoggerFactoryAdapter Members + + /// + /// Get a ILog instance by type + /// + /// + /// + public ILog GetLogger(Type type) + { + return s_nopLogger; + } + + /// + /// Get a ILog instance by type name + /// + /// + /// + ILog ILoggerFactoryAdapter.GetLogger(string name) + { + return s_nopLogger; + + } + + #endregion + } +} diff --git a/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs b/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs index 6a941c1..e033eb2 100644 --- a/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs +++ b/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs @@ -19,7 +19,7 @@ #endregion using System.Collections.Specialized; -using System.Configuration; +using namespace Common.Logging.Configuration { diff --git a/src/Common.Logging/Logging/IConfigurationReader.cs b/src/Common.Logging/Logging/IConfigurationReader.cs index 2822a08..52dd1c1 100644 --- a/src/Common.Logging/Logging/IConfigurationReader.cs +++ b/src/Common.Logging/Logging/IConfigurationReader.cs @@ -18,8 +18,6 @@ #endregion -using System.Configuration; - namespace Common.Logging { diff --git a/src/CommonAssemblyInfo.cs b/src/CommonAssemblyInfo.cs index 2e686b2..6502561 100644 --- a/src/CommonAssemblyInfo.cs +++ b/src/CommonAssemblyInfo.cs @@ -22,7 +22,7 @@ [assembly: AssemblyTrademarkAttribute("Apache License, Version 2.0")] [assembly: AssemblyCultureAttribute("")] [assembly: AssemblyVersionAttribute("2.1.2")] -[assembly: AssemblyConfigurationAttribute("net-4.0.win32; release")] -[assembly: AssemblyInformationalVersionAttribute("2.1.2; net-4.0.win32; release")] +[assembly: AssemblyConfigurationAttribute("monotouch; release")] +[assembly: AssemblyInformationalVersionAttribute("2.1.2; monotouch; release")] [assembly: AssemblyDelaySignAttribute(false)] From 7267b3aeecb6844b73276d06a5654281ed6006c1 Mon Sep 17 00:00:00 2001 From: adamnation Date: Sat, 26 Jan 2013 12:38:11 -0800 Subject: [PATCH 09/12] ported unit tests and unit test utils to monotouch, monotouch logger tests pass --- .DS_Store | Bin 0 -> 6148 bytes Common.Logging.2010-net40.userprefs | 20 +++ .../Common.Logging.MonoTouch/.DS_Store | Bin 0 -> 6148 bytes .../Common.Logging.MonoTouch.Tests.csproj | 117 +++++++++++++ .../Common.Logging.MonoTouch.Tests/Info.plist | 26 +++ .../SImple/AbstractSimpleLoggerTests.cs | 98 +++++++++++ .../SImple/AbstractSimpleLoggerTestsBase.cs | 46 +++++ .../Logging/SImple/ConsoleOutLoggerTests.cs | 56 +++++++ .../Common.Logging.MonoTouch.Tests/Main.cs | 20 +++ .../Settings.bundle/Common.Logging | 6 + .../Settings.bundle/Common.Logging.plist | 18 ++ .../Settings.bundle/Root.plist | 62 +++++++ .../UnitTestAppDelegate.cs | 46 +++++ .../Common.Logging.MonoTouch.sln | 42 +++++ .../Common.Logging.MonoTouch.userprefs | 20 +++ .../MonoTouchConfigurationReader.cs | 15 +- .../AbstractSimpleLoggerFactoryAdapter.cs | 23 +++ .../Simple/ConsoleOutLoggerFactoryAdapter.cs | 133 +++++++++------ .../Common.Logging.TestUtlis.MonoTouch.csproj | 55 ++++++ .../Logging/ILogTestsBase.cs | 158 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 35 ++++ .../TestUtil/SerializationTestUtils.cs | 135 +++++++++++++++ .../TestUtil/TraceEventArgs.cs | 54 ++++++ .../DefaultConfigurationReader.cs | 2 +- 24 files changed, 1128 insertions(+), 59 deletions(-) create mode 100644 .DS_Store create mode 100644 Common.Logging.2010-net40.userprefs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/.DS_Store create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Info.plist create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTestsBase.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/ConsoleOutLoggerTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Main.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Root.plist create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/UnitTestAppDelegate.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.userprefs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Common.Logging.TestUtlis.MonoTouch.csproj create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Logging/ILogTestsBase.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Properties/AssemblyInfo.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/SerializationTestUtils.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/TraceEventArgs.cs diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3f7458e825eaa9b9961b0f54c1df1144c174bb31 GIT binary patch literal 6148 zcmeHK!AiqG5Z!I7Ca4e(LXS(&MbaG9f`W6l7)EdL zlzhJ(aP4)GiTb-({`d*xB8)Y}+~*4$?`IErM)5N%EU;lr6$Ed5ojk zt>#5k%<~|cY0q_3jKHILKg-6zhZH?XlVWt|G?z=S>$R2Vb;`C{cF)|lIz4yG(zY!7 zNVcrw*2%?HKYA*kUn(P`#MPo58d&wOE5?KsU17>a7DhT>=0$U|Jh+tR*l<5&DFcLGXY{lL}~3C6yS`q{F + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/.DS_Store b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7aa841e61ef691454ea60f0e00559aaf347b2067 GIT binary patch literal 6148 zcmeHK%}N6?5T0n&Eh_9q=yCB}N^1*x@UYYh9u$NYJXq0PSGo(eD|Sl{wYvBYK8J7P z^Y~2?i^X~s(V3Eblle(9A2itzk!p^j8j(vx4jQ9kWr47Hp=-$oD(SeJtx|pQU^GqYl_41@Gk79A#z{CyM8jvs?|5Ov|LzO zU2}>>XQO+T45D=0OhsgSEhRxt!drpHahDYn2H0?w0+UT<+ z%Hm76G?~Yg%VOCyFzcUZ znkd46Fdz&F1OJu*dr3I!|CRwMTo@1rzGHyT2M>+Wx0oB$M+Z9n1OOIb)&ia15}e~% z^eyHF;ejZV3N)$8J~5O@huyPrzQx?2NhhUO#yocAkH?GBtHbW;a8kZO>4gDdV4i_x zGj#d>Kg3^V;Uj-OMMlDaF!0A1P=!{z)kIPDZv9do-?bjv6&ef2<*Y!U&wT`7z~@Lw eJB{CC9dW+J+#t`wcAXBC4*^Yxbi%+7Fz^o44oEuy literal 0 HcmV?d00001 diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj new file mode 100644 index 0000000..bcbd71d --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj @@ -0,0 +1,117 @@ + + + + Debug + iPhoneSimulator + 10.0.0 + 2.0 + {04F451AA-0CEE-4971-AC7E-9D401114F1E2} + {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Exe + Common.Logging.MonoTouch.Tests + Resources + CommonLoggingMonoTouchTests + + + True + full + False + bin\iPhoneSimulator\Debug + DEBUG; + prompt + 4 + False + True + True + None + + + none + True + bin\iPhoneSimulator\Release + prompt + 4 + False + None + + + True + full + False + bin\iPhone\Debug + DEBUG; + prompt + 4 + False + iPhone Developer + True + True + + + none + True + bin\iPhone\Release + prompt + 4 + False + iPhone Developer + + + none + True + bin\iPhone\Ad-Hoc + prompt + 4 + True + False + Automatic:AdHoc + iPhone Distribution + + + none + True + bin\iPhone\AppStore + prompt + 4 + False + iPhone Distribution + Automatic:AppStore + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F} + Common.Logging.MonoTouch + + + {B928FD65-4E80-4F9D-96D0-830EDB3092DB} + Common.Logging.TestUtlis.MonoTouch + + + \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Info.plist b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Info.plist new file mode 100644 index 0000000..8653860 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Info.plist @@ -0,0 +1,26 @@ + + + + + UIDeviceFamily + + 1 + 2 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + MinimumOSVersion + 3.2 + + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTests.cs new file mode 100644 index 0000000..ddf2bdd --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTests.cs @@ -0,0 +1,98 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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 NUnit.Framework; + +namespace Common.Logging.Simple +{ + /// + /// Tests the class. + /// + /// Erich Eichinger + [TestFixture] + public class AbstractSimpleLoggerTests + { + private class ConcreteLogger : AbstractSimpleLogger + { + public ConcreteLogger(string logName, LogLevel logLevel, bool showlevel, bool showDateTime, bool showLogName, string dateTimeFormat) : base(logName, logLevel, showlevel, showDateTime, showLogName, dateTimeFormat) + {} + + protected override void WriteInternal(LogLevel level, object message, Exception exception) + { + throw new NotImplementedException(); + } + } + + private class ConcreteLoggerFactory : AbstractSimpleLoggerFactoryAdapter + { + public ConcreteLoggerFactory(NameValueCollection properties) : base(properties) + { + } + + protected override ILog CreateLogger(string name, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) + { + return new ConcreteLogger(name, level, showLevel, showDateTime, showLogName, dateTimeFormat); + } + } + + [Test] + public void IsSerializable() + { + Assert.IsTrue(SerializationTestUtils.IsSerializable()); + } + + [Test] + public void DefaultValues() + { + AbstractSimpleLogger logger; + logger = (AbstractSimpleLogger)new ConcreteLoggerFactory(null).GetLogger("x"); + Assert.AreEqual("x", logger.Name); + Assert.AreEqual(true, logger.ShowLogName); + Assert.AreEqual(true, logger.ShowDateTime); + Assert.AreEqual(true, logger.ShowLevel); + Assert.AreEqual(false, logger.HasDateTimeFormat); + Assert.AreEqual(string.Empty, logger.DateTimeFormat); + Assert.AreEqual(LogLevel.All, logger.CurrentLogLevel); + } + + [Test] + public void ConfiguredValues() + { + NameValueCollection props = new NameValueCollection(); + props["showLogName"] = "false"; + props["showLevel"] = "false"; + props["showDateTime"] = "false"; + props["dateTimeFormat"] = "MM"; + props["level"] = "Info"; + + AbstractSimpleLogger logger; + logger = (AbstractSimpleLogger)new ConcreteLoggerFactory(props).GetLogger("x"); + Assert.AreEqual("x", logger.Name); + Assert.AreEqual(false, logger.ShowLogName); + Assert.AreEqual(false, logger.ShowDateTime); + Assert.AreEqual(false, logger.ShowLevel); + Assert.AreEqual(true, logger.HasDateTimeFormat); + Assert.AreEqual("MM", logger.DateTimeFormat); + Assert.AreEqual(LogLevel.Info, logger.CurrentLogLevel); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTestsBase.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTestsBase.cs new file mode 100644 index 0000000..c6f4e30 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTestsBase.cs @@ -0,0 +1,46 @@ +#region License + +/* + * Copyright © 2002-2007 the original author or authors. + * + * 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.Collections.Specialized; + +namespace Common.Logging.Simple +{ + /// + /// Base class that exercises the basic api of the simple loggers. + /// To simplify testing derived classes you should derive your fixtures from this base fixture + /// + /// Mark Pollack + public abstract class AbstractSimpleLoggerTestsBase : ILogTestsBase + { + private static int count; + + protected static NameValueCollection CreateProperties() + { + NameValueCollection properties = new NameValueCollection(); + properties["showDateTime"] = "true"; + // if ((count % 2) == 0) + { + properties["dateTimeFormat"] = "yyyy/MM/dd HH:mm:ss:fff"; + } + count++; + return properties; + } + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/ConsoleOutLoggerTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/ConsoleOutLoggerTests.cs new file mode 100644 index 0000000..960e512 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/ConsoleOutLoggerTests.cs @@ -0,0 +1,56 @@ +#region License + +/* + * Copyright © 2002-2007 the original author or authors. + * + * 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 NUnit.Framework; + +namespace Common.Logging.Simple +{ + /// + /// Exercises the ConsoleOutLogger implementation. + /// + /// Mark Pollack + [TestFixture] + public class ConsoleOutLoggerTests : AbstractSimpleLoggerTestsBase + { + protected override ILoggerFactoryAdapter GetLoggerFactoryAdapter() + { + return new ConsoleOutLoggerFactoryAdapter(CreateProperties()); + } + + /// + /// Basic checks specific to ConsoleOutLogger + /// + [Test] + public void AssertDefaultSettings() + { + ILog log = LogManager.GetCurrentClassLogger(); + + Assert.IsNotNull(log); + Assert.AreEqual(typeof(ConsoleOutLogger),log.GetType()); + + // Can we call level checkers with no exceptions? + Assert.IsTrue(log.IsDebugEnabled); + Assert.IsTrue(log.IsInfoEnabled); + Assert.IsTrue(log.IsWarnEnabled); + Assert.IsTrue(log.IsErrorEnabled); + Assert.IsTrue(log.IsFatalEnabled); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Main.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Main.cs new file mode 100644 index 0000000..d8e37cf --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Main.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using MonoTouch.Foundation; +using MonoTouch.UIKit; + +namespace Common.Logging.MonoTouch.Tests +{ + public class Application + { + // This is the main entry point of the application. + static void Main (string[] args) + { + // if you want to use a different Application Delegate class from "UnitTestAppDelegate" + // you can specify it here. + UIApplication.Main (args, null, "UnitTestAppDelegate"); + } + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging new file mode 100644 index 0000000..6631ffa --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist new file mode 100644 index 0000000..5812f1e --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist @@ -0,0 +1,18 @@ + + + + + dateTimeFormat + + logLevel + LogLevel.Debug + logName + log4net for monotouch tests + showDateTime + true + showLevel + true + showLogName + true + + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Root.plist b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Root.plist new file mode 100644 index 0000000..943b963 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Root.plist @@ -0,0 +1,62 @@ + + + + + PreferenceSpecifiers + + + Type + PSGroupSpecifier + Title + Group + + + Type + PSTextFieldSpecifier + Title + Name + KeyboardType + Alphabet + AutocapitalizationType + None + AutocorrectionType + No + IsSecure + + Key + name_preference + DefaultValue + + + + Type + PSToggleSwitchSpecifier + Title + Enabled + Key + enabled_preference + DefaultValue + + + + Type + PSSliderSpecifier + MaximumValue + 1 + MaximumValueImage + + MinimumValue + 0 + MinimumValueImage + + Key + slider_preference + DefaultValue + 0.5 + + + StringsTable + Root + + + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/UnitTestAppDelegate.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/UnitTestAppDelegate.cs new file mode 100644 index 0000000..4dc25a7 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/UnitTestAppDelegate.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using MonoTouch.Foundation; +using MonoTouch.UIKit; +using MonoTouch.NUnit.UI; + +namespace Common.Logging.MonoTouch.Tests +{ + // The UIApplicationDelegate for the application. This class is responsible for launching the + // User Interface of the application, as well as listening (and optionally responding) to + // application events from iOS. + [Register ("UnitTestAppDelegate")] + public partial class UnitTestAppDelegate : UIApplicationDelegate + { + // class-level declarations + UIWindow window; + TouchRunner runner; + + // + // This method is invoked when the application has loaded and is ready to run. In this + // method you should instantiate the window, load the UI into it and then make the window + // visible. + // + // You have 17 seconds to return from this method, or iOS will terminate your application. + // + public override bool FinishedLaunching (UIApplication app, NSDictionary options) + { + // create a new window instance based on the screen size + window = new UIWindow (UIScreen.MainScreen.Bounds); + runner = new TouchRunner (window); + + // register every tests included in the main application/assembly + runner.Add (System.Reflection.Assembly.GetExecutingAssembly ()); + + window.RootViewController = new UINavigationController (runner.GetViewController ()); + + // make the window visible + window.MakeKeyAndVisible (); + + return true; + } + } +} + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln index b4b3f8d..c8eef57 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln @@ -3,12 +3,54 @@ Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.MonoTouch", "Common.Logging.MonoTouch\Common.Logging.MonoTouch.csproj", "{DD9F81C2-BA9A-4212-9249-2300C62AFF6F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.MonoTouch.Tests", "Common.Logging.MonoTouch.Tests\Common.Logging.MonoTouch.Tests.csproj", "{04F451AA-0CEE-4971-AC7E-9D401114F1E2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.TestUtlis.MonoTouch", "Common.Logging.TestUtlis.MonoTouch\Common.Logging.TestUtlis.MonoTouch.csproj", "{B928FD65-4E80-4F9D-96D0-830EDB3092DB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU + Debug|iPhoneSimulator = Debug|iPhoneSimulator + Release|iPhoneSimulator = Release|iPhoneSimulator + Debug|iPhone = Debug|iPhone + Release|iPhone = Release|iPhone + Ad-Hoc|iPhone = Ad-Hoc|iPhone + AppStore|iPhone = AppStore|iPhone EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Ad-Hoc|iPhone.ActiveCfg = Ad-Hoc|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Ad-Hoc|iPhone.Build.0 = Ad-Hoc|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.AppStore|iPhone.ActiveCfg = AppStore|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.AppStore|iPhone.Build.0 = AppStore|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Debug|iPhone.ActiveCfg = Debug|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Debug|iPhone.Build.0 = Debug|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Release|Any CPU.ActiveCfg = Release|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Release|Any CPU.Build.0 = Release|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Release|iPhone.ActiveCfg = Release|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Release|iPhone.Build.0 = Release|iPhone + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator + {04F451AA-0CEE-4971-AC7E-9D401114F1E2}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.AppStore|iPhone.Build.0 = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Debug|iPhone.Build.0 = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|Any CPU.Build.0 = Release|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|iPhone.ActiveCfg = Release|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|iPhone.Build.0 = Release|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|iPhoneSimulator.Build.0 = Release|Any CPU {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Debug|Any CPU.Build.0 = Debug|Any CPU {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.userprefs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.userprefs new file mode 100644 index 0000000..6012b78 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.userprefs @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs index 3aed086..9af4ba1 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs @@ -18,6 +18,8 @@ #endregion using MonoTouch.Foundation; +using Common.Logging.Simple; +using System.Collections.Specialized; namespace Common.Logging.Configuration { @@ -40,9 +42,16 @@ public class MonoTouchConfigurationReader : IConfigurationReader ///

/// /// - public object GetSection(string sectionName) - { - return new NSDictionary (NSBundle.MainBundle.PathForResource (sectionName, null)); + public object GetSection (string sectionName) + { + NameValueCollection properties = new NameValueCollection(); + var nsDict = new NSDictionary (NSBundle.MainBundle.PathForResource (sectionName, null)); + foreach (var key in nsDict.Keys) + { + properties.Add(key.ToString(), nsDict[key].ToString()); + } + + return new LogSetting(typeof(ConsoleOutLoggerFactoryAdapter), properties); } } } \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs index f2a36f9..ae9aea1 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs @@ -20,6 +20,7 @@ using System.Collections.Specialized; using Common.Logging.Factory; +using Common.Logging.Configuration; namespace Common.Logging.Simple { @@ -136,6 +137,28 @@ public string DateTimeFormat set { _dateTimeFormat = value; } } + /// + /// Initializes a new instance of the class. + /// + /// + /// Looks for level, showDateTime, showLogName, dateTimeFormat items from + /// for use when the GetLogger methods are called. + /// for more information on how to use the + /// standard .NET application configuraiton file (App.config/Web.config) + /// to configure this adapter. + /// + /// The name value collection, typically specified by the user in + /// a configuration section named common/logging. + protected AbstractSimpleLoggerFactoryAdapter(NameValueCollection properties) + :this( + ArgUtils.TryParseEnum(LogLevel.All, ArgUtils.GetValue(properties, "level")), + ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showDateTime")), + ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showLogName")), + ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showLevel")), + ArgUtils.GetValue(properties, "dateTimeFormat", string.Empty) + ) + {} + /// /// Initializes a new instance of the class with /// default settings for the loggers created by this factory. diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs index 02b5455..1719a7d 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs @@ -23,59 +23,82 @@ namespace Common.Logging.Simple { - /// - /// Factory for creating instances that write data to . - /// - /// - /// - /// Below is an example how to configure this adapter: - /// - /// <configuration> - /// - /// <configSections> - /// <sectionGroup name="common"> - /// <section name="logging" - /// type="Common.Logging.ConfigurationSectionHandler, Common.Logging" - /// requirePermission="false" /> - /// </sectionGroup> - /// </configSections> - /// - /// <common> - /// <logging> - /// <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging"> - /// <arg key="level" value="ALL" /> - /// </factoryAdapter> - /// </logging> - /// </common> - /// - /// </configuration> - /// - /// - /// - /// - /// - /// - /// Gilles Bayon - /// Mark Pollack - /// Erich Eichinger - public class ConsoleOutLoggerFactoryAdapter : AbstractSimpleLoggerFactoryAdapter - { - - /// - /// Initializes a new instance of the class with - /// default settings for the loggers created by this factory. - /// - public ConsoleOutLoggerFactoryAdapter(LogLevel level, bool showDateTime, bool showLogName, bool showLevel, string dateTimeFormat) - : base(level, showDateTime, showLogName, showLevel, dateTimeFormat) - { } - - /// - /// Creates a new instance. - /// - protected override ILog CreateLogger(string name, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) - { - ILog log = new ConsoleOutLogger(name, level, showLevel, showDateTime, showLogName, dateTimeFormat); - return log; - } - } + /// + /// Factory for creating instances that write data to . + /// + /// + /// + /// Below is an example how to configure this adapter: + /// + /// <configuration> + /// + /// <configSections> + /// <sectionGroup name="common"> + /// <section name="logging" + /// type="Common.Logging.ConfigurationSectionHandler, Common.Logging" + /// requirePermission="false" /> + /// </sectionGroup> + /// </configSections> + /// + /// <common> + /// <logging> + /// <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging"> + /// <arg key="level" value="ALL" /> + /// </factoryAdapter> + /// </logging> + /// </common> + /// + /// </configuration> + /// + /// + /// + /// + /// + /// + /// Gilles Bayon + /// Mark Pollack + /// Erich Eichinger + public class ConsoleOutLoggerFactoryAdapter : AbstractSimpleLoggerFactoryAdapter + { + /// + /// Initializes a new instance of the class using default + /// settings. + /// + public ConsoleOutLoggerFactoryAdapter() + : base(null) + { } + + /// + /// Initializes a new instance of the class. + /// + /// + /// Looks for level, showDateTime, showLogName, dateTimeFormat items from + /// for use when the GetLogger methods are called. + /// for more information on how to use the + /// standard .NET application configuraiton file (App.config/Web.config) + /// to configure this adapter. + /// + /// The name value collection, typically specified by the user in + /// a configuration section named common/logging. + public ConsoleOutLoggerFactoryAdapter(NameValueCollection properties) + : base(properties) + { } + + /// + /// Initializes a new instance of the class with + /// default settings for the loggers created by this factory. + /// + public ConsoleOutLoggerFactoryAdapter(LogLevel level, bool showDateTime, bool showLogName, bool showLevel, string dateTimeFormat) + : base(level, showDateTime, showLogName, showLevel, dateTimeFormat) + { } + + /// + /// Creates a new instance. + /// + protected override ILog CreateLogger(string name, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) + { + ILog log = new ConsoleOutLogger(name, level, showLevel, showDateTime, showLogName, dateTimeFormat); + return log; + } + } } diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Common.Logging.TestUtlis.MonoTouch.csproj b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Common.Logging.TestUtlis.MonoTouch.csproj new file mode 100644 index 0000000..4bbee5d --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Common.Logging.TestUtlis.MonoTouch.csproj @@ -0,0 +1,55 @@ + + + + Debug + AnyCPU + 10.0.0 + 2.0 + {B928FD65-4E80-4F9D-96D0-830EDB3092DB} + {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Common.Logging.TestUtlis.MonoTouch + Resources + Common.Logging.TestUtlis.MonoTouch + + + True + full + False + bin\Debug + DEBUG; + prompt + 4 + False + + + none + True + bin\Release + prompt + 4 + False + + + + + + + + + + + + + + + + + + + + {DD9F81C2-BA9A-4212-9249-2300C62AFF6F} + Common.Logging.MonoTouch + + + \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Logging/ILogTestsBase.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Logging/ILogTestsBase.cs new file mode 100644 index 0000000..ac155e1 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Logging/ILogTestsBase.cs @@ -0,0 +1,158 @@ +#region License + +/* + * Copyright © 2002-2006 the original author or authors. + * + * 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.Diagnostics; +using System.Reflection; +using System.Security; +using System.Security.Permissions; +using NUnit.Framework; +using Common.TestUtil; + +namespace Common.Logging +{ + /// + /// Generic tests that can be applied to any log implementation by + /// subclassing and defining the property LogObject. + /// + /// + /// Exercises basic API of the ILog implemetation. + /// + /// Mark Pollack + // [TestFixture] + public abstract class ILogTestsBase + { + [SetUp] + public virtual void SetUp() + { + //Security = new SecurityTemplate(true); + LogManager.Reset(); + LogManager.Adapter = GetLoggerFactoryAdapter(); + } + + protected abstract ILoggerFactoryAdapter GetLoggerFactoryAdapter(); + + [Test] + public void LoggingWithNullParameters() + { + Console.Out.WriteLine("Executing Test " + MethodBase.GetCurrentMethod().Name); + ILog log = LogManager.GetCurrentClassLogger(); + + log.Trace((object)null); + log.Trace((object)null, null); + log.Trace((Action)null); + log.Trace((Action)null, null); + log.Trace(null, (Action)null); + log.Trace(null, (Action)null, null); + log.TraceFormat((string)null); + log.TraceFormat(null, (Exception)null); + log.TraceFormat((IFormatProvider)null, null); + log.TraceFormat((IFormatProvider)null, null, (Exception)null); + + log.Debug((object)null); + log.Debug((object)null, null); + log.Debug((Action)null); + log.Debug((Action)null, null); + log.Debug(null, (Action)null); + log.Debug(null, (Action)null, null); + log.Debug(null); + log.Debug(null, (Exception)null); + log.Debug((IFormatProvider)null, null); + log.Debug((IFormatProvider)null, null, (Exception)null); + + } + + [Test] + public void CanCallIsEnabledFromNamedLog() + { + CanCallIsEnabled(LogManager.GetLogger("loggerName")); + } + + [Test] + public void CanLogMessageFromNamedLog() + { + CanLogMessage(LogManager.GetLogger("logger2Name")); + } + + [Test] + public void CanLogMessageWithExceptionFromNamedLog() + { + ILog log = LogManager.GetLogger("logger3Name"); + CanLogMessageWithException(log); + } + + [Test] + public void CanLogMessageWithExceptionFromTypeLog() + { + ILog log = LogManager.GetCurrentClassLogger(); + CanLogMessageWithException(log); + } + + protected virtual void CanCallIsEnabled(ILog log) + { + bool b; + b = log.IsTraceEnabled; + b = log.IsDebugEnabled; + b = log.IsInfoEnabled; + b = log.IsWarnEnabled; + b = log.IsErrorEnabled; + b = log.IsFatalEnabled; + } + + protected virtual void CanLogMessage(ILog log) + { + log.Trace("Hi Trace"); + log.Debug("Hi Debug"); + log.Info("Hi Info"); + log.Warn("Hi Warn"); + log.Error("Hi Error"); + log.Fatal("Hi Fatal"); + } + +#if NET_3_0 + protected virtual void CanLogMessageWithException(ILog log) + { + log.Trace(m => m("Hi {0}", "dude")); + log.Debug(m => m("Hi {0}", "dude"), new ArithmeticException()); + log.Info(m => m("Hi {0}", "dude"), new ArithmeticException()); + log.Warn(m => m("Hi {0}", "dude"), new ArithmeticException()); + log.Error(m => m("Hi {0}", "dude"), new ArithmeticException()); + log.Fatal(m => m("Hi {0}", "dude"), new ArithmeticException()); + } +#else + protected virtual void CanLogMessageWithException(ILog log) + { + log.TraceFormat("Hi {0}", new ArithmeticException(), "Trace"); + log.DebugFormat("Hi {0}", new ArithmeticException(), "Debug"); + log.InfoFormat("Hi {0}", new ArithmeticException(), "Info"); + log.WarnFormat("Hi {0}", new ArithmeticException(), "Warn"); + log.ErrorFormat("Hi {0}", new ArithmeticException(), "Error"); + log.FatalFormat("Hi {0}", new ArithmeticException(), "Fatal"); + } +#endif + + protected delegate TResult Func(TArg1 arg1); + + protected MethodBase GetMember(Func action) + { + return action.Method; + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Properties/AssemblyInfo.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3e71e62 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1ae77e17-60c0-473f-be37-657900f0f8e2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/SerializationTestUtils.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/SerializationTestUtils.cs new file mode 100644 index 0000000..7b645bb --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/SerializationTestUtils.cs @@ -0,0 +1,135 @@ +#region License + +/* + * Copyright 2002-2007 the original author or authors. + * + * 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.IO; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; +using NUnit.Framework; + +namespace Common.Logging +{ + /// + /// Utilities for testing serializability of objects. + /// + /// + /// Exposes static methods for use in other test cases. + /// + /// Erich Eichinger + [TestFixture] + public sealed class SerializationTestUtils + { + #region Test Ourselves + + [Test] + [ExpectedException(typeof(SerializationException))] + public void WithNonSerializableObject() + { + TestObject o = new TestObject(); + Assert.IsFalse(o is ISerializable); + Assert.IsFalse(IsSerializable(o)); + TrySerialization(o); + } + + [Test] + public void WithSerializableObject() + { + SerializableTestObject pA = new SerializableTestObject("propA"); + Assert.IsTrue(IsSerializable(pA)); + TrySerialization(pA); + SerializableTestObject pB = SerializeAndDeserialize(pA); + Assert.IsFalse(ReferenceEquals(pA, pB)); + Assert.AreEqual(pA.SomeProperty, pB.SomeProperty); + } + + #endregion + + /// + /// Attempts to serialize the specified object to an in-memory stream. + /// + /// the object to serialize + public static void TrySerialization(object o) + { + using (Stream stream = new MemoryStream()) + { + BinaryFormatter bformatter = new BinaryFormatter(); + bformatter.Serialize(stream, o); + } + } + + /// + /// Tests whether the specified object is serializable. + /// + /// the object to test. + /// true if the object is serializable, otherwise false. + public static bool IsSerializable(object o) + { + return o == null ? true : o.GetType().IsSerializable; + } + + /// + /// Tests whether instances of the specified type are serializable. + /// + /// true if the type is serializable, otherwise false. + public static bool IsSerializable() + { + return typeof(T).IsSerializable; + } + + /// + /// Serializes the specified object to an in-memory stream, and returns + /// the result of deserializing the object stream. + /// + /// the object to use. + /// the deserialized object. + public static T SerializeAndDeserialize(T o) + { + using (Stream stream = new MemoryStream()) + { + BinaryFormatter bformatter = new BinaryFormatter(); + bformatter.Serialize(stream, o); + stream.Flush(); + + stream.Seek(0, SeekOrigin.Begin); + T o2 = (T)bformatter.Deserialize(stream); + return o2; + } + } + + #region Test Classes + + private class TestObject + { + } + + [Serializable] + private class SerializableTestObject + { + public readonly string SomeProperty; + + public SerializableTestObject(string someProperty) + { + SomeProperty = someProperty; + } + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/TraceEventArgs.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/TraceEventArgs.cs new file mode 100644 index 0000000..a6ca827 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/TraceEventArgs.cs @@ -0,0 +1,54 @@ +using System; +using System.Diagnostics; +using System.Text; + +namespace Common.TestUtil +{ + public class TraceEventArgs + { + public string Source; + public string Category; + public int? Id; + public object[] Data; + public object Format; + public object[] Args; + public Guid? RelatedActivityId; + + public TraceEventArgs(string source, string category, int? id, object message, object[] args, object[] data, Guid? relatedActivityId) + { + Source = source; + Category = category; + Id = id; + Format = message; + Args = args; + Data = data; + RelatedActivityId = relatedActivityId; + } + + public string FormattedMessage + { + get + { + string msg = null; + if (Format == null && Data != null) + { + StringBuilder sb = new StringBuilder(); + foreach(object d in Data) + { + sb.Append(d); + } + msg = sb.ToString(); + } + else + { + msg = "" + Format; + } + if (Args != null) + { + return string.Format(msg, Args); + } + return msg; + } + } + } +} \ No newline at end of file diff --git a/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs b/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs index e033eb2..6a941c1 100644 --- a/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs +++ b/src/Common.Logging/Logging/Configuration/DefaultConfigurationReader.cs @@ -19,7 +19,7 @@ #endregion using System.Collections.Specialized; -using +using System.Configuration; namespace Common.Logging.Configuration { From f7aaa5957af2f0147399cd8627ca7af6b13c27dc Mon Sep 17 00:00:00 2001 From: adamnation Date: Sun, 27 Jan 2013 12:32:11 -0800 Subject: [PATCH 10/12] fix issue with reading plist config, adding in more unit tests, removing use of Rhino.Mock --- .../Common.Logging.MonoTouch/.DS_Store | Bin 6148 -> 6148 bytes .../Common.Logging.MonoTouch.Tests.csproj | 5 +- .../Logging/Configuration/ArgUtilsTests.cs | 158 ++++++ .../MonoTouchConfigurationReaderTests.cs | 38 ++ .../Logging/Factory/AbstractLoggerTests.cs | 479 ++++++++++++++++++ .../Settings.bundle/Common.Logging.plist | 2 + .../MonoTouchConfigurationReader.cs | 2 +- 7 files changed, 682 insertions(+), 2 deletions(-) create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/ArgUtilsTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Factory/AbstractLoggerTests.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/.DS_Store b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/.DS_Store index 7aa841e61ef691454ea60f0e00559aaf347b2067..833f29edcb67c4b91dad89b81a8f7cb25fdc1353 100644 GIT binary patch delta 21 ccmZoMXffEZiIKy|%uGkY$joH(E=Dgg07$k5C;$Ke delta 21 ccmZoMXffEZiIKzD&`3wY#Kd^>E=Dgg07zE`9{>OV diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj index bcbd71d..20b5e63 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj @@ -91,7 +91,6 @@ - @@ -99,10 +98,14 @@ + + + + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/ArgUtilsTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/ArgUtilsTests.cs new file mode 100644 index 0000000..61a70d6 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/ArgUtilsTests.cs @@ -0,0 +1,158 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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.Runtime.Serialization; +using NUnit.Framework; + +namespace Common.Logging.Configuration +{ + /// + /// + /// Erich Eichinger + [TestFixture] + public class ArgUtilsTests + { + [Test] + public void GetValue() + { + NameValueCollection nvc = new NameValueCollection(); + nvc["key"] = "value"; + + Assert.AreEqual( null, ArgUtils.GetValue(null, "key")); + Assert.AreEqual("value", ArgUtils.GetValue(nvc, "key")); + Assert.AreEqual(null, ArgUtils.GetValue(nvc, "wrongkey")); + Assert.AreEqual("defaultValue", ArgUtils.GetValue(null, "wrongkey", "defaultValue")); + Assert.AreEqual("defaultValue", ArgUtils.GetValue(nvc, "wrongkey", "defaultValue")); + } + + [Test] + public void Coalesce() + { + Assert.AreEqual(null, ArgUtils.Coalesce()); + Assert.AreEqual(null, ArgUtils.Coalesce(null, null)); + Assert.AreEqual("x", ArgUtils.Coalesce(string.Empty, null, "x")); + // null predicate causes the use the default predicate of (v!=null) + Assert.AreEqual(string.Empty, ArgUtils.Coalesce( (Predicate)null, string.Empty, (string)null, "x")); + Assert.AreEqual(null, ArgUtils.Coalesce( delegate(object v) { return v != null; } )); + Assert.AreEqual(string.Empty, ArgUtils.Coalesce( delegate(object v) { return v != null; }, null, string.Empty, "x")); + } + + [Test] + public void TryParseEnum() + { + Assert.Throws( + Is.TypeOf().And.Message.EqualTo( string.Format("Type '{0}' is not an enum type", typeof(int).FullName) ) + , delegate + { + ArgUtils.TryParseEnum((int) 1, "0"); + } + ); + + Assert.AreEqual( LogLevel.Fatal, ArgUtils.TryParseEnum(LogLevel.All, "fatal") ); + Assert.AreEqual( LogLevel.Debug, ArgUtils.TryParseEnum(LogLevel.Debug, "invalid value") ); + Assert.AreEqual( LogLevel.Debug, ArgUtils.TryParseEnum(LogLevel.Debug, null) ); + } + + [Test] + public void TryParse() + { + Assert.Throws( + Is.TypeOf() + .And.Message.EqualTo(string.Format("There is no parser registered for type {0}", typeof(object).FullName)) + , delegate + { + ArgUtils.TryParse(new object(), "0"); + } + ); + + Assert.AreEqual( true, ArgUtils.TryParse(false, "trUE") ); + Assert.AreEqual( 1, ArgUtils.TryParse(2, "1") ); + Assert.AreEqual( 2, ArgUtils.TryParse(2, "2invalidnumber1") ); + Assert.AreEqual( (short)1, ArgUtils.TryParse((short)2, "1") ); + Assert.AreEqual( (long)1, ArgUtils.TryParse((long)2, "1") ); + Assert.AreEqual( (float)1, ArgUtils.TryParse((float)2, "1") ); + Assert.AreEqual( (double)1, ArgUtils.TryParse((double)2, "1") ); + Assert.AreEqual( (decimal)1, ArgUtils.TryParse((decimal)2, "1") ); + } + + [Test] + public void AssertIsAssignable() + { + Assert.Throws( + Is.TypeOf() + .And.Message.EqualTo(new ArgumentNullException("valType").Message) + , delegate + { + ArgUtils.AssertIsAssignable("arg", null); + } + ); + + Assert.Throws( + Is.TypeOf() + .And.Message.EqualTo(new ArgumentOutOfRangeException("this", this.GetType(),string.Format("Type '{0}' of parameter '{1}' is not assignable to target type '{2}'" + , this.GetType().AssemblyQualifiedName + , "this" + , typeof (ISerializable).AssemblyQualifiedName) ).Message) + , delegate + { + ArgUtils.AssertIsAssignable("this", this.GetType()); + } + ); + + Type type = typeof(Int32); + Assert.AreSame(type, ArgUtils.AssertIsAssignable("arg", type)); + } + + [Test] + public void AssertNotNullThrowsArgumentNullException() + { + object tmp = new object(); + Assert.AreSame(tmp, ArgUtils.AssertNotNull("arg", tmp)); + Assert.Throws(Is.TypeOf() + .And.Message.EqualTo(new ArgumentNullException("tmp").Message), + delegate { ArgUtils.AssertNotNull("tmp", (object)null); }); + Assert.Throws(Is.TypeOf().And.Message.EqualTo(new ArgumentNullException("tmp", "message msgarg").Message), + delegate { ArgUtils.AssertNotNull("tmp", (object)null, "message {0}", "msgarg"); }); + } + + [Test] + public void Guard() + { + ArgUtils.Guard(delegate { }, "format {0}", "fmtarg"); + Assert.AreEqual(1, ArgUtils.Guard(delegate { return 1; }, "format {0}", "fmtarg")); + + Assert.Throws(Is.TypeOf() + .And.Message.EqualTo("innermessage"), + delegate + { + ArgUtils.Guard(delegate { throw new ConfigurationException("innermessage"); }, "format {0}", "fmtarg"); + }); + + Assert.Throws(Is.TypeOf() + .And.Message.EqualTo("format fmtarg"), + delegate + { + ArgUtils.Guard(delegate { throw new ArgumentException("innermessage"); }, "format {0}", "fmtarg"); + }); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs new file mode 100644 index 0000000..d4e9c5d --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs @@ -0,0 +1,38 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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.Collections.Specialized; +using NUnit.Framework; + +namespace Common.Logging.Configuration +{ + /// + /// + /// Erich Eichinger + [TestFixture] + public class MonoTouchConfigurationReaderTests + { + [Test] + public void ReadsAppConfig() + { + Assert.AreEqual("FromAppConfig", ((NameValueCollection)new MonoTouchConfigurationReader().GetSection("Settings.bundle/Common.Logging.plist"))["appConfigCheck"]); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Factory/AbstractLoggerTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Factory/AbstractLoggerTests.cs new file mode 100644 index 0000000..1f19f42 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Factory/AbstractLoggerTests.cs @@ -0,0 +1,479 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * 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.Globalization; +using System.Reflection; +using NUnit.Framework; +//using Rhino.Mocks; +//using Rhino.Mocks.Interfaces; +using FormatMessageCallback = System.Action; +//using Is=Rhino.Mocks.Constraints.Is; + +namespace Common.Logging.Factory +{ + /// + /// Tests for class. In particular ensures, that all ILog.XXX methods + /// correctuly route to the single WriteInternal delegate. + /// + [TestFixture] + public class AbstractLoggerTests + { + [Test] + public void IsSerializable() + { + SerializationTestUtils.IsSerializable(); + } + + [Test] + public void ImplementsAllMethodsForAllLevels() + { + string[] logLevels = Exclude(Enum.GetNames(typeof (LogLevel)), "All", "Off"); + + foreach (string logLevel in logLevels) + { + MethodInfo[] logMethods = GetLogMethodSignatures(logLevel); + for (int i = 0; i < logLevels.Length; i++) + { + Assert.IsNotNull(logMethods[i], + "Method with signature #{0} not implemented for level {1}", i, logLevel); + } + } + } + + [Test] + public void LogsMessage() + { + string[] logLevels = Exclude(Enum.GetNames(typeof(LogLevel)), "All", "Off"); + + foreach (string logLevel in logLevels) + { + LogsMessage(logLevel); + } + } + + /// + /// Ensures, that all interface methods delegate to Write() with correct level + arguments + /// and that arguments are still not evaluated up to this point (e.g. calling ToString()) + /// + private static void LogsMessage(string levelName) + { + //MockRepository mocks = new MockRepository(); + + TestLogger log = new TestLogger(); + Exception ex = new Exception(); + + + MethodInfo[] logMethods = GetLogMethodSignatures(levelName); + + LogLevel logLevel = (LogLevel)Enum.Parse(typeof(LogLevel), levelName); + + Invoke(log, logMethods[0], "messageObject0"); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("messageObject0", log.LastMessage); + Assert.AreEqual(null, log.LastException); + + Invoke(log, logMethods[1], "messageObject1", ex); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("messageObject1", log.LastMessage); + Assert.AreEqual(ex, log.LastException); + + Invoke(log, logMethods[2], "format2 {0}", new object[] { "arg2" }); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("format2 arg2", log.LastMessage); + Assert.AreEqual(null, log.LastException); + + Invoke(log, logMethods[3], "format3 {0}", ex, new object[] { "arg3" }); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("format3 arg3", log.LastMessage); + Assert.AreEqual(ex, log.LastException); + + Invoke(log, logMethods[4], CultureInfo.CreateSpecificCulture("de-de"), "format4 {0}", new object[] { 4.1 }); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("format4 4,1", log.LastMessage); + Assert.AreEqual(null, log.LastException); + + Invoke(log, logMethods[5], CultureInfo.CreateSpecificCulture("de-de"), "format5 {0}", ex, new object[] { 5.1 }); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("format5 5,1", log.LastMessage); + Assert.AreEqual(ex, log.LastException); + + Invoke(log, logMethods[6], TestFormatMessageCallback.MessageCallback("message6")); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("message6", log.LastMessage); + Assert.AreEqual(null, log.LastException); + + Invoke(log, logMethods[7], TestFormatMessageCallback.MessageCallback("message7"), ex); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("message7", log.LastMessage); + Assert.AreEqual(ex, log.LastException); + + Invoke(log, logMethods[8], CultureInfo.CreateSpecificCulture("de-de"), TestFormatMessageCallback.MessageCallback("format8 {0}", new object[] { 8.1 })); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("format8 8,1", log.LastMessage); + Assert.AreEqual(null, log.LastException); + + Invoke(log, logMethods[9], CultureInfo.CreateSpecificCulture("de-de"), TestFormatMessageCallback.MessageCallback("format9 {0}", new object[] { 9.1 }), ex); + Assert.AreEqual(logLevel, log.LastLogLevel); + Assert.AreEqual("format9 9,1", log.LastMessage); + Assert.AreEqual(ex, log.LastException); + } + /* + [Test] + public void WriteIsCalledWithCorrectLogLevel() + { + string[] logLevels = Exclude(Enum.GetNames(typeof(LogLevel)), "All", "Off"); + + foreach (string logLevel in logLevels) + { + WriteIsCalledWithCorrectLogLevel(logLevel); + } + } + + /// + /// Ensures, that all interface methods delegate to Write() with correct level + arguments + /// and that arguments are still not evaluated up to this point (e.g. calling ToString()) + /// + private static void WriteIsCalledWithCorrectLogLevel(string levelName) + { + MockRepository mocks = new MockRepository(); + + AbstractTestLogger log = (AbstractTestLogger)mocks.PartialMock(typeof(AbstractTestLogger)); + Exception ex = (Exception)mocks.StrictMock(typeof(Exception)); + object messageObject = mocks.StrictMock(typeof(object)); + object formatArg = mocks.StrictMock(typeof(object)); + FormatMessageCallback failCallback = TestFormatMessageCallback.FailCallback(); + + MethodInfo[] logMethods = GetLogMethodSignatures(levelName); + + LogLevel logLevel = (LogLevel) Enum.Parse(typeof (LogLevel), levelName); + + using (mocks.Ordered()) + { + log.Log(logLevel, null, null); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); + log.Log(logLevel, null, ex); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); + log.Log(logLevel, null, null); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); + log.Log(logLevel, null, ex); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); + log.Log(logLevel, null, null); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); + log.Log(logLevel, null, ex); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); + log.Log(logLevel, null, null); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); + log.Log(logLevel, null, ex); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); + log.Log(logLevel, null, null); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); + log.Log(logLevel, null, ex); + LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); + } + mocks.ReplayAll(); + + Invoke(log, logMethods[0], messageObject); + Invoke(log, logMethods[1], messageObject, ex); + Invoke(log, logMethods[2], "format", new object[] { formatArg }); + Invoke(log, logMethods[3], "format", ex, new object[] { formatArg }); + Invoke(log, logMethods[4], CultureInfo.InvariantCulture, "format", new object[] { formatArg }); + Invoke(log, logMethods[5], CultureInfo.InvariantCulture, "format", ex, new object[] { formatArg }); + Invoke(log, logMethods[6], failCallback); + Invoke(log, logMethods[7], failCallback, ex); + Invoke(log, logMethods[8], CultureInfo.InvariantCulture, failCallback); + Invoke(log, logMethods[9], CultureInfo.InvariantCulture, failCallback, ex); + + mocks.VerifyAll(); + } +*/ + /* + [Test] + public void WriteAndEvaluateOnlyWhenLevelEnabled() + { + string[] logLevels = Exclude(Enum.GetNames(typeof(LogLevel)), "All", "Off"); + + foreach (string logLevel in logLevels) + { + WriteAndEvaluateOnlyWhenLevelEnabled(logLevel); + } + } + + /// + /// This test ensures, that for a given loglevel + /// a) AbstractLogger.Write is not called if that loglevel is disabled + /// b) No argument is evaluated (e.g. calling ToString()) if that loglevel is disabled + /// + private static void WriteAndEvaluateOnlyWhenLevelEnabled(string levelName) + { + MockRepository mocks = new MockRepository(); + + AbstractLogger log = (AbstractLogger)mocks.StrictMock(typeof(AbstractLogger)); + Exception ex = (Exception)mocks.StrictMock(typeof(Exception)); + object messageObject = mocks.StrictMock(typeof(object)); + object formatArg = mocks.StrictMock(typeof(object)); + FormatMessageCallback failCallback = TestFormatMessageCallback.FailCallback(); + + MethodInfo[] logMethods = GetLogMethodSignatures(levelName); + + using (mocks.Ordered()) + { + Invoke(log, logMethods[0], messageObject); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[1], messageObject, ex); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[2], "format", new object[] { formatArg }); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[3], "format", ex, new object[] { formatArg }); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[4], CultureInfo.InvariantCulture, "format", new object[] { formatArg }); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[5], CultureInfo.InvariantCulture, "format", ex, new object[] { formatArg }); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[6], failCallback); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[7], failCallback, ex); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[8], CultureInfo.InvariantCulture, failCallback); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + Invoke(log, logMethods[9], CultureInfo.InvariantCulture, failCallback, ex); + LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation); + Expect.Call(IsLevelEnabled(log, levelName)).Return(false); + } + mocks.ReplayAll(); + + Invoke(log, logMethods[0], messageObject); + Invoke(log, logMethods[1], messageObject, ex); + Invoke(log, logMethods[2], "format", new object[] {formatArg}); + Invoke(log, logMethods[3], "format", ex, new object[] { formatArg }); + Invoke(log, logMethods[4], CultureInfo.InvariantCulture, "format", new object[] {formatArg}); + Invoke(log, logMethods[5], CultureInfo.InvariantCulture, "format", ex, new object[] { formatArg }); + Invoke(log, logMethods[6], failCallback); + Invoke(log, logMethods[7], failCallback, ex); + Invoke(log, logMethods[8], CultureInfo.InvariantCulture, failCallback); + Invoke(log, logMethods[9], CultureInfo.InvariantCulture, failCallback, ex); + + mocks.VerifyAll(); + } +*/ + private static bool IsLevelEnabled(ILog log, string logLevelName) + { + switch(logLevelName) + { + case "Trace": + return log.IsTraceEnabled; + case "Debug": + return log.IsDebugEnabled; + case "Info": + return log.IsInfoEnabled; + case "Warn": + return log.IsWarnEnabled; + case "Error": + return log.IsErrorEnabled; + case "Fatal": + return log.IsFatalEnabled; + default: + throw new ArgumentOutOfRangeException("logLevelName", logLevelName, "unknown log level "); + } + } + + private static readonly Type[][] methodSignatures = + { + new Type[] {typeof (object)}, + new Type[] {typeof (object), typeof (Exception)}, + new Type[] {typeof (string), typeof (object[])}, + new Type[] {typeof (string), typeof (Exception), typeof (object[])}, + new Type[] {typeof (IFormatProvider), typeof (string), typeof (object[])}, + new Type[] {typeof (IFormatProvider), typeof (string), typeof (Exception), typeof (object[])}, + new Type[] {typeof (FormatMessageCallback)}, + new Type[] {typeof (FormatMessageCallback), typeof (Exception)}, + new Type[] {typeof (IFormatProvider), typeof (FormatMessageCallback)}, + new Type[] {typeof (IFormatProvider), typeof (FormatMessageCallback), typeof (Exception)} + }; + + private static MethodInfo[] GetLogMethodSignatures(string levelName) + { + return new MethodInfo[] + { + typeof (ILog).GetMethod(levelName, methodSignatures[0]), + typeof (ILog).GetMethod(levelName, methodSignatures[1]), + typeof (ILog).GetMethod(levelName + "Format", methodSignatures[2]), + typeof (ILog).GetMethod(levelName + "Format", methodSignatures[3]), + typeof (ILog).GetMethod(levelName + "Format", methodSignatures[4]), + typeof (ILog).GetMethod(levelName + "Format", methodSignatures[5]), + typeof (ILog).GetMethod(levelName, methodSignatures[6]), + typeof (ILog).GetMethod(levelName, methodSignatures[7]), + typeof (ILog).GetMethod(levelName, methodSignatures[8]), + typeof (ILog).GetMethod(levelName, methodSignatures[9]) + }; + } + + private static void Invoke(object target, MethodInfo method, params object[] args) + { + method.Invoke(target, args); + } + + #region TestFormatMessageCallback Utility Class + + private class TestFormatMessageCallback + { + private readonly bool throwOnInvocation; + private readonly string messageToReturn; + private readonly object[] argsToReturn; + + private TestFormatMessageCallback(bool throwOnInvocation) + { + this.throwOnInvocation = throwOnInvocation; + } + + private TestFormatMessageCallback(string messageToReturn, object[] args) + { + this.messageToReturn = messageToReturn; + this.argsToReturn = args; + } + + public static FormatMessageCallback FailCallback() + { + return new FormatMessageCallback(new TestFormatMessageCallback(true).FormatMessage); + } + + public static FormatMessageCallback MessageCallback(string message, params object[] args) + { + return new FormatMessageCallback(new TestFormatMessageCallback(message, args).FormatMessage); + } + + private void FormatMessage(FormatMessageHandler fmh) + { + if (throwOnInvocation) + { + Assert.Fail(); + } + fmh(messageToReturn, argsToReturn); + } + } + + #endregion + + private static string[] Exclude(string[] arr, params string[] exclude) + { + ArrayList result = new ArrayList(); + foreach (string s in arr) + { + if (0 > Array.BinarySearch(exclude, s)) + { + result.Add(s); + } + } + return (string[]) result.ToArray(typeof (string)); + } + + public class TestLogger : AbstractTestLogger + { + public LogLevel LastLogLevel; + public string LastMessage; + public Exception LastException; + + protected override WriteHandler GetWriteHandler() + { + return new WriteHandler(Log); + } + + protected override void WriteInternal(LogLevel level, object message, Exception exception) + { + Assert.Fail("must never been called - Log() should be called"); + } + + public override void Log(LogLevel level, object message, Exception exception) + { + LastLogLevel = level; + LastMessage = message.ToString(); + LastException = exception; + } + } + + public abstract class AbstractTestLogger : AbstractLogger + { + protected override void WriteInternal(LogLevel level, object message, Exception exception) + { + Log(level, message, exception); + } + + public abstract void Log(LogLevel level, object message, Exception exception); + + /// + /// Checks if this logger is enabled for the level. + /// + public override bool IsTraceEnabled + { + get { return true; } + } + + /// + /// Checks if this logger is enabled for the level. + /// + public override bool IsDebugEnabled + { + get { return true; } + } + + /// + /// Checks if this logger is enabled for the level. + /// + public override bool IsErrorEnabled + { + get { return true; } + } + + /// + /// Checks if this logger is enabled for the level. + /// + public override bool IsFatalEnabled + { + get { return true; } + } + + /// + /// Checks if this logger is enabled for the level. + /// + public override bool IsInfoEnabled + { + get { return true; } + } + + /// + /// Checks if this logger is enabled for the level. + /// + public override bool IsWarnEnabled + { + get { return true; } + } + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist index 5812f1e..5443b06 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist @@ -2,6 +2,8 @@ + appConfigCheck + FromAppConfig dateTimeFormat logLevel diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs index 9af4ba1..4d4175e 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs @@ -51,7 +51,7 @@ public object GetSection (string sectionName) properties.Add(key.ToString(), nsDict[key].ToString()); } - return new LogSetting(typeof(ConsoleOutLoggerFactoryAdapter), properties); + return properties; } } } \ No newline at end of file From 7a876c40da0280d04cee9042b7495d0fadba84ee Mon Sep 17 00:00:00 2001 From: adamnation Date: Sun, 27 Jan 2013 14:02:19 -0800 Subject: [PATCH 11/12] adding more tests, fixed a bug in config reader --- .../AssemblyInfo.cs | 29 ++ .../Common.Logging.MonoTouch.Tests.csproj | 8 + .../ExceptionsTest.cs | 450 ++++++++++++++++++ .../MonoTouchConfigurationReaderTests.cs | 4 +- .../Logging/LogManagerTests.cs | 63 +++ .../Logging/LoggingExceptionTests.cs | 42 ++ .../Logging/MissingCtorFactoryAdapter.cs | 49 ++ .../MethodInvokePerformanceTests.cs | 62 +++ .../Settings.bundle/Common.Logging.plist | 6 +- .../StandardsComplianceTest.cs | 109 +++++ .../StopWatch.cs | 99 ++++ .../MonoTouchConfigurationReader.cs | 2 +- 12 files changed, 916 insertions(+), 7 deletions(-) create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/AssemblyInfo.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/ExceptionsTest.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LogManagerTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LoggingExceptionTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/MissingCtorFactoryAdapter.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/MethodInvokePerformanceTests.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StandardsComplianceTest.cs create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StopWatch.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/AssemblyInfo.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/AssemblyInfo.cs new file mode 100644 index 0000000..1c11957 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/AssemblyInfo.cs @@ -0,0 +1,29 @@ +using System.Reflection; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly: AssemblyTitle("")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly: AssemblyVersion("1.0.*")] + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj index 20b5e63..7e79e5b 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj @@ -101,6 +101,14 @@ + + + + + + + + diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/ExceptionsTest.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/ExceptionsTest.cs new file mode 100644 index 0000000..f4affbc --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/ExceptionsTest.cs @@ -0,0 +1,450 @@ +#region License + +/* + * Copyright © 2002-2007 the original author or authors. + * + * 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 + +#region Imports + +using System; +using System.Globalization; +using System.IO; +using System.Reflection; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; +using NUnit.Framework; + +#endregion + +namespace Common +{ + /// + /// Tests the various exception classes. + /// + /// + /// + /// Shamelessly lifted from the NAnt test suite. + /// + /// + /// Rick Evans + /// $Id:$ + public abstract class ExceptionsTest : StandardsComplianceTest + { + protected ExceptionsTest() + { + CheckedType = typeof (Exception); + } + + #region Tests + + [Test] + public void TestStandardsCompliance() + { + ProcessAssembly(AssemblyToCheck); + } + + [Test] + public void TestThisTest() + { + ProcessAssembly(Assembly.GetAssembly(GetType())); + } + + #endregion + + #region Methods + + protected override void CheckStandardsCompliance(Assembly assembly, Type t) + { + // check to see that the exception is correctly named, with "Exception" at the end + bool nameIsValid = t.Name.EndsWith("Exception"); + Assert.IsTrue(nameIsValid, t.Name + " class name must end with Exception."); + if (t.IsAbstract) + { + return; + } + // Does the exception have the 3 standard constructors? + // Default constructor + CheckPublicConstructor(t, "()"); + // Constructor with a single string parameter + CheckPublicConstructor(t, "(string message)", typeof (String)); + // Constructor with a string and an inner exception + CheckPublicConstructor(t, "(string message, Exception inner)", + typeof (String), typeof (Exception)); + // check to see if the serialization constructor is present + // if exception is sealed, constructor should be private + // if exception is not sealed, constructor should be protected + if (t.IsSealed) + { + // check to see if the private serialization constructor is present... + CheckPrivateConstructor(t, "(SerializationInfo info, StreamingContext context)", + typeof (SerializationInfo), + typeof (StreamingContext)); + } + else + { + // check to see if the protected serialization constructor is present... + CheckProtectedConstructor(t, "(SerializationInfo info, StreamingContext context)", + typeof (SerializationInfo), + typeof (StreamingContext)); + } + // check to see if the type is marked as serializable + Assert.IsTrue(t.IsSerializable, t.Name + " is not serializable, missing [Serializable]?"); + // check to see if there are any public fields. These should be properties instead... + FieldInfo[] publicFields = + t.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); + if (publicFields.Length != 0) + { + foreach (FieldInfo fieldInfo in publicFields) + { + Assert.Fail(t.Name + "." + fieldInfo.Name + + " is a public field, should be exposed through property instead."); + } + } + // If this exception has any fields, check to make sure it has a + // version of GetObjectData. If not, it does't serialize those fields. + FieldInfo[] fields = + t.GetFields(BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public | + BindingFlags.Instance); + if (fields.Length != 0) + { + if ( + t.GetMethod("GetObjectData", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance) == + null) + { + Assert.Fail(t.Name + " does not implement GetObjectData but has private fields."); + } + } + if (!t.IsAbstract) + { + CheckInstantiation(t); + } + } + + /// + /// Checks the public constructor. + /// + /// The type + /// The description. + /// The parameters. + private void CheckPublicConstructor(Type t, string description, params Type[] parameters) + { + // locate constructor + ConstructorInfo ci = + t.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, parameters, + null); + // fail if constructor does not exist + Assert.IsNotNull(ci, t.Name + description + " is a required constructor."); + // fail if constructor is private + Assert.IsFalse(ci.IsPrivate, t.Name + description + " is private, must be public."); + // fail if constructor is protected + Assert.IsFalse(ci.IsFamily, t.Name + description + " is internal, must be public."); + // fail if constructor is internal + Assert.IsFalse(ci.IsAssembly, t.Name + description + " is internal, must be public."); + // fail if constructor is protected internal + Assert.IsFalse(ci.IsFamilyOrAssembly, t.Name + description + " is protected internal, must be public."); + // sanity check to make sure the constructor is public + Assert.IsTrue(ci.IsPublic, t.Name + description + " is not public, must be public."); + } + + private void CheckProtectedConstructor(Type t, string description, params Type[] parameters) + { + // locate constructor + ConstructorInfo ci = + t.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, parameters, + null); + // fail if constructor does not exist + Assert.IsNotNull(ci, t.Name + description + " is a required constructor."); + // fail if constructor is public + Assert.IsFalse(ci.IsPublic, t.Name + description + " is public, must be protected."); + // fail if constructor is private + Assert.IsFalse(ci.IsPrivate, t.Name + description + " is private, must be public or protected."); + // fail if constructor is internal + Assert.IsFalse(ci.IsAssembly, t.Name + description + " is internal, must be protected."); + // fail if constructor is protected internal + Assert.IsFalse(ci.IsFamilyOrAssembly, t.Name + description + " is protected internal, must be protected."); + // sanity check to make sure the constructor is protected + Assert.IsTrue(ci.IsFamily, t.Name + description + " is not protected, must be protected."); + } + + private void CheckPrivateConstructor(Type t, string description, params Type[] parameters) + { + // locate constructor + ConstructorInfo ci = + t.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, parameters, + null); + // fail if constructor does not exist + Assert.IsNotNull(ci, t.Name + description + " is a required constructor."); + // fail if constructor is public + Assert.IsFalse(ci.IsPublic, t.Name + description + " is public, must be private."); + // fail if constructor is protected + Assert.IsFalse(ci.IsFamily, t.Name + description + " is protected, must be private."); + // fail if constructor is internal + Assert.IsFalse(ci.IsAssembly, t.Name + description + " is internal, must be private."); + // fail if constructor is protected internal + Assert.IsFalse(ci.IsFamilyOrAssembly, t.Name + description + " is protected internal, must be private."); + // sanity check to make sure the constructor is private + Assert.IsTrue(ci.IsPrivate, t.Name + description + " is not private, must be private."); + } + + /// + /// If we've got here, then the standards compliance tests have passed... + /// + /// The exception type being tested. + private void CheckInstantiation(Type t) + { + // attempt to instantiate the 3 standard ctors... + ConstructorInfo ctor = t.GetConstructor(Type.EmptyTypes); + try + { + ctor.Invoke(null); + } + catch (Exception ex) + { + Assert.Fail("Ctor () for '" + t.Name + "' threw an exception : " + ex.Message); + } + ctor = t.GetConstructor(new Type[] {typeof (string)}); + try + { + Exception ex = (Exception) ctor.Invoke(new object[] {"My Fingers Turn To Fists"}); + Assert.IsNotNull(ex.Message, t.Name + "'s Message was null."); + } + catch (Exception ex) + { + Assert.Fail("Ctor (string) for '" + t.Name + "' threw an exception : " + ex.Message); + } + ctor = t.GetConstructor(new Type[] {typeof (string), typeof (Exception)}); + try + { + Exception ex = + (Exception) ctor.Invoke(new object[] {"My Fingers Turn To Fists", new FormatException("Bing")}); + Assert.IsNotNull(ex.Message, t.Name + "'s Message was null."); + Assert.IsNotNull(ex.InnerException, t.Name + "'s InnerException was null."); + Assert.AreEqual("Bing", ex.InnerException.Message); + } + catch (Exception ex) + { + Assert.Fail("Ctor (string, Exception) for '" + t.Name + "' threw an exception : " + ex.Message); + } + // test the serialization ctor + try + { + ctor = t.GetConstructor(new Type[] {typeof (string)}); + Exception ex = (Exception) ctor.Invoke(new object[] {"HungerHurtsButStarvingWorks"}); + BinaryFormatter bf = new BinaryFormatter(); + MemoryStream ms = new MemoryStream(); + bf.Serialize(ms, ex); + ms.Seek(0, 0); + Exception inex = (Exception) bf.Deserialize(ms); + Assert.IsNotNull(inex); + } + catch (Exception ex) + { + Assert.Fail("Ctor (Serialization) for '" + t.Name + "' threw an exception : " + ex.Message); + } + } + + #endregion + + #region Properties + + /// + /// We will test all of the exceptions in this assembly for their correctness. + /// + protected Assembly AssemblyToCheck + { + get { return _assemblyToCheck; } + set { _assemblyToCheck = value; } + } + + #endregion + + private Assembly _assemblyToCheck = null; + } + + #region Inner Class : SimpleTestException + + /// + /// Do nothing exception to verify that the exception tester + /// is working correctly. + /// + [Serializable] + public class SimpleTestException : ApplicationException + { + #region Public Instance Constructors + + public SimpleTestException() + { + } + + public SimpleTestException(string message) : base(message) + { + } + + public SimpleTestException(string message, Exception inner) + : base(message, inner) + { + } + + #endregion Public Instance Constructors + + #region Protected Instance Constructors + + // deserialization constructor + protected SimpleTestException( + SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + + #endregion Protected Instance Constructors + } + + #endregion + + #region Inner Class : TestException + + /// + /// Exception to verify that the exception tester is working correctly. + /// + [Serializable] + public class TestException : ApplicationException, ISerializable + { + #region Private Instance Fields + + private int _value; + + #endregion Private Instance Fields + + #region Public Instance Constructors + + public TestException() + { + } + + public TestException(string message) : base(message) + { + } + + public TestException(string message, Exception inner) + : base(message, inner) + { + } + + // constructors that take the added value + public TestException(string message, int value) : base(message) + { + _value = value; + } + + #endregion Public Instance Constructors + + #region Protected Instance Constructors + + // deserialization constructor + protected TestException(SerializationInfo info, StreamingContext context) : base(info, context) + { + _value = info.GetInt32("Value"); + } + + #endregion Protected Instance Constructors + + #region Public Instance Properties + + public int Value + { + get { return _value; } + } + + #endregion Public Instance Properties + + #region Override implementation of ApplicationException + + // Called by the frameworks during serialization + // to fetch the data from an object. + public override void GetObjectData( + SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + info.AddValue("Value", _value); + } + + // overridden Message property. This will give the + // proper textual representation of the exception, + // with the added field value. + public override string Message + { + get + { + // NOTE: should be localized... + string s = + string.Format( + CultureInfo.InvariantCulture, "Value: {0}", _value); + return base.Message + Environment.NewLine + s; + } + } + + #endregion Override implementation of ApplicationException + } + + #endregion + + #region Inner Class : SealedTestException + + /// + /// Exception to verify that the exception tester is working on + /// sealed exception. + /// + [Serializable] + public sealed class SealedTestException : TestException + { + #region Public Instance Constructors + + public SealedTestException() + { + } + + public SealedTestException(string message) : base(message) + { + } + + public SealedTestException(string message, Exception inner) + : base(message, inner) + { + } + + // constructors that take the added value + public SealedTestException(string message, int value) + : base(message, value) + { + } + + #endregion Public Instance Constructors + + #region Private Instance Constructors + + // deserialization constructor + private SealedTestException( + SerializationInfo info, StreamingContext context) + : base(info, context) + { + } + + #endregion Private Instance Constructors + } + + #endregion +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs index d4e9c5d..3810209 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs @@ -20,7 +20,7 @@ using System.Collections.Specialized; using NUnit.Framework; - +using Common.Logging.Simple; namespace Common.Logging.Configuration { /// @@ -32,7 +32,7 @@ public class MonoTouchConfigurationReaderTests [Test] public void ReadsAppConfig() { - Assert.AreEqual("FromAppConfig", ((NameValueCollection)new MonoTouchConfigurationReader().GetSection("Settings.bundle/Common.Logging.plist"))["appConfigCheck"]); + Assert.IsNotNull(((ConsoleOutLoggerFactoryAdapter)new MonoTouchConfigurationReader().GetSection("Settings.bundle/Common.Logging.plist"))); } } } \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LogManagerTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LogManagerTests.cs new file mode 100644 index 0000000..9af4fe9 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LogManagerTests.cs @@ -0,0 +1,63 @@ +#region License + +/* + * Copyright © 2002-2007 the original author or authors. + * + * 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.Diagnostics; +using Common.Logging.Configuration; +using Common.Logging.Simple; +using NUnit.Framework; +//using Rhino.Mocks; + +namespace Common.Logging +{ + /// + /// Tests for LogManager that exercise the basic API and check for error conditions. + /// + /// Mark Pollack + [TestFixture] + public class LogManagerTests + { + //public MockRepository mocks; + + [SetUp] + public void SetUp() + { + LogManager.Reset(); + //mocks = new MockRepository(); + } + + [Test] + public void AdapterProperty() + { + ILoggerFactoryAdapter adapter = new NoOpLoggerFactoryAdapter(); + LogManager.Adapter = adapter; + Assert.AreSame(adapter, LogManager.Adapter); + + Assert.Throws(delegate { LogManager.Adapter = null; }); + } + + [Test] + public void ConfigureFromSettings () + { + var logger = LogManager.GetCurrentClassLogger(); + logger.Info("Hi from plist config!"); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LoggingExceptionTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LoggingExceptionTests.cs new file mode 100644 index 0000000..11fb8eb --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LoggingExceptionTests.cs @@ -0,0 +1,42 @@ +#region License + +/* + * Copyright © 2002-2007 the original author or authors. + * + * 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.Reflection; +using NUnit.Framework; + +namespace Common.Logging +{ + /// + /// Test that exceptions declared in Common.Logging meet coding standards. + /// + /// Mark Pollack + /// $Id:$ + [TestFixture] + public class LoggingExceptionTests : ExceptionsTest + { + [TestFixtureSetUp] + public void FixtureSetUp() + { + AssemblyToCheck = Assembly.GetAssembly(typeof (ConfigurationException)); + } + + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/MissingCtorFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/MissingCtorFactoryAdapter.cs new file mode 100644 index 0000000..32132e9 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/MissingCtorFactoryAdapter.cs @@ -0,0 +1,49 @@ +#region License + +/* + * Copyright © 2002-2007 the original author or authors. + * + * 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 Common.Logging +{ + /// + /// Class that does not have constructors used by LogManager to create the adapter. + /// + /// Mark Pollack + /// $Id:$ + public class MissingCtorFactoryAdapter : ILoggerFactoryAdapter + { + private string foo; + + public MissingCtorFactoryAdapter(string foo) + { + this.foo = foo; + } + + public ILog GetLogger(Type type) + { + throw new NotImplementedException(); + } + + public ILog GetLogger(string name) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/MethodInvokePerformanceTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/MethodInvokePerformanceTests.cs new file mode 100644 index 0000000..5e9c06d --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/MethodInvokePerformanceTests.cs @@ -0,0 +1,62 @@ +using System; +using NUnit.Framework; + +namespace Common +{ + internal interface IWriteHandler + { + void PerformanceTestTarget(int z, object message, Exception ex); + } + + [TestFixture, Explicit] + public class MethodInvokePerformanceTests : IWriteHandler + { + private delegate void WriteHandler(int x, object message, Exception ex); + + [Test] + public void DelegatePerformanceTest() + { + int runs = 5000000; + + StopWatch sw; + sw = new StopWatch(); + using(sw.Start("Time:{0}")) + { + for (int i = 0; i < runs; i++) + { + PerformanceTestTarget(1, null, null); + } + } +// Trace.WriteLine( string.Format("Time:{0}", sw.Elapsed.TotalSeconds) ); + + WriteHandler writeHandler = new WriteHandler(PerformanceTestTarget); + using(sw.Start("Time:{0}")) + { + for (int i = 0; i < runs; i++) + { + writeHandler(1, null, null); + } + } +// Trace.WriteLine(string.Format("Time:{0}", sw.Elapsed.TotalSeconds)); + + IWriteHandler writeHandler2 = this; + using(sw.Start("Time:{0}")) + { + for (int i = 0; i < runs; i++) + { + writeHandler2.PerformanceTestTarget(1, null, null); + } + } +// Trace.WriteLine(string.Format("Time:{0}", sw.Elapsed.TotalSeconds)); + } + + public void PerformanceTestTarget(int z, object message, Exception ex) + { + double x = 2.1; + for(int i=0;i<10;i++) + { + x = x * x * x; + } + } + } +} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist index 5443b06..29f6bd0 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist @@ -2,12 +2,10 @@ - appConfigCheck - FromAppConfig dateTimeFormat - + yyyy-MM-dd HH:MI:SS logLevel - LogLevel.Debug + Debug logName log4net for monotouch tests showDateTime diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StandardsComplianceTest.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StandardsComplianceTest.cs new file mode 100644 index 0000000..2b832e0 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StandardsComplianceTest.cs @@ -0,0 +1,109 @@ +#region License + +/* + * Copyright 2004-2008 the original author or authors. + * + * 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 + +#region Imports + +using System; +using System.Reflection; + +#endregion + +namespace Common +{ + /// + /// Base class for tests that check standards compliance. + /// + /// Rick Evans + public abstract class StandardsComplianceTest + { + #region Constructor (s) / Destructor + + /// + /// Creates a new instance of the class. + /// + /// + /// + /// This is an class, and as such has no publicly visible + /// constructors. + /// + /// + protected StandardsComplianceTest() + { + } + + #endregion + + #region Properties + + protected Type CheckedType + { + get { return checkedType; } + set { checkedType = value; } + } + + #endregion + + #region Methods + + private bool IsCheckedType(Type type) + { + if (CheckedType.IsInterface) + { + Type iface = type.GetInterface(CheckedType.Name, false); + return iface != null; + } + else + { + Type baseType = null; + while ((baseType = type.BaseType) != null) + { + if (baseType == CheckedType) + { + return true; + } + type = baseType; + } + } + return false; + } + + protected void ProcessAssembly(Assembly a) + { + foreach (Type t in a.GetTypes()) + { + if (IsCheckedType(t)) + { + CheckStandardsCompliance(a, t); + } + } + } + + protected abstract void CheckStandardsCompliance( + Assembly assembly, Type t); + + #endregion + + #region Fields + + private Type checkedType; + + #endregion + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StopWatch.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StopWatch.cs new file mode 100644 index 0000000..ab09bd0 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StopWatch.cs @@ -0,0 +1,99 @@ +#region License + +/* + * Copyright © 2002-2008 the original author or authors. + * + * 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 + +#region Imports + +using System; + +#endregion + +namespace Common +{ + /// + /// A simple StopWatch implemetion for use in Performance Tests + /// + /// + /// The following example shows the usage: + /// + /// StopWatch watch = new StopWatch(); + /// using (watch.Start("Duration: {0}")) + /// { + /// // do some work... + /// } + /// + /// The format string passed to the start method is used to print the result message. + /// The example above will print Duration: 0.123s. + /// + /// Erich Eichinger + public class StopWatch + { + private DateTime _startTime; + private TimeSpan _elapsed; + + private class Stopper : IDisposable + { + private readonly StopWatch _owner; + private readonly string _format; + + public Stopper(StopWatch owner, string format) + { + _owner = owner; + _format = format; + } + + public void Dispose() + { + _owner.Stop(_format); + GC.SuppressFinalize(this); + } + } + + /// + /// Starts the timer and returns and "handle" that must be disposed to stop the timer. + /// + /// the output format string, that is used to render the result message + /// the handle to dispose for stopping the timer + public IDisposable Start(string outputFormat) + { + Stopper stopper = new Stopper(this, outputFormat); + _startTime = DateTime.Now; + return stopper; + } + + private void Stop(string outputFormat) + { + _elapsed = DateTime.Now.Subtract(_startTime); + if (outputFormat != null) + { + Console.WriteLine(outputFormat, _elapsed); + } + } + + public DateTime StartTime + { + get { return _startTime; } + } + + public TimeSpan Elapsed + { + get { return _elapsed; } + } + } +} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs index 4d4175e..46529d9 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs @@ -51,7 +51,7 @@ public object GetSection (string sectionName) properties.Add(key.ToString(), nsDict[key].ToString()); } - return properties; + return new ConsoleOutLoggerFactoryAdapter(properties); } } } \ No newline at end of file From 9911c18b6179e113416c29432b60e56a102b9b13 Mon Sep 17 00:00:00 2001 From: adamnation Date: Sun, 14 Jul 2013 19:33:23 -0700 Subject: [PATCH 12/12] moving solution to root of repo, including all common source files from src/Common.Logging --- ...oTouch.sln => Common.Logging.MonoTouch.sln | 28 +- Common.Logging.MonoTouch.userprefs | 18 + .../Common.Logging.MonoTouch => }/.DS_Store | Bin 6148 -> 6148 bytes src/Common.Logging.MonoTouch/.DS_Store | Bin 0 -> 6148 bytes .../AssemblyInfo.cs | 0 .../Common.Logging.MonoTouch.Tests.csproj | 8 +- .../ExceptionsTest.cs | 0 .../Common.Logging.MonoTouch.Tests/Info.plist | 0 .../Logging/Configuration/ArgUtilsTests.cs | 0 .../MonoTouchConfigurationReaderTests.cs | 46 +- .../Logging/Factory/AbstractLoggerTests.cs | 0 .../Logging/LogManagerTests.cs | 0 .../Logging/LoggingExceptionTests.cs | 0 .../Logging/MissingCtorFactoryAdapter.cs | 0 .../SImple/AbstractSimpleLoggerTests.cs | 0 .../SImple/AbstractSimpleLoggerTestsBase.cs | 0 .../Logging/SImple/ConsoleOutLoggerTests.cs | 0 .../Common.Logging.MonoTouch.Tests/Main.cs | 0 .../MethodInvokePerformanceTests.cs | 0 .../Settings.bundle/Common.Logging | 0 .../Settings.bundle/Common.Logging.plist | 0 .../Settings.bundle/Root.plist | 0 .../StandardsComplianceTest.cs | 0 .../StopWatch.cs | 0 .../UnitTestAppDelegate.cs | 0 .../Common.Logging.MonoTouch.csproj | 135 +++ .../Common.Logging.MonoTouch.userprefs | 20 - .../Common.Logging.MonoTouch/AssemblyDoc.cs | 31 - .../Common.Logging.MonoTouch/AssemblyInfo.cs | 5 - .../Common.Logging.MonoTouch.csproj | 84 -- .../Common.Logging.MonoTouch/LogManager.cs | 333 ------ .../Logging/Configuration/ArgUtils.cs | 316 ----- .../Logging/Configuration/LogSetting.cs | 77 -- .../Logging/Configuration/NamespaceDoc.cs | 31 - .../Logging/ConfigurationException.cs | 84 -- .../Logging/ConfigurationSectionHandler.cs | 232 ---- .../Logging/CoverageExcludeAttribute.cs | 32 - .../AbstractCachingLoggerFactoryAdapter.cs | 132 --- .../Logging/Factory/AbstractLogger.cs | 1033 ----------------- .../Logging/Factory/NamespaceDoc.cs | 31 - .../Logging/FormatMessageHandler.cs | 32 - .../Logging/IConfigurationReader.cs | 49 - .../Common.Logging.MonoTouch/Logging/ILog.cs | 649 ----------- .../Logging/ILoggerFactoryAdapter.cs | 49 - .../Logging/LogLevel.cs | 62 - .../Logging/LogManager.cs | 333 ------ .../Logging/NamespaceDoc.cs | 31 - .../Logging/Simple/AbstractSimpleLogger.cs | 263 ----- .../AbstractSimpleLoggerFactoryAdapter.cs | 191 --- .../Logging/Simple/ConsoleOutLogger.cs | 64 - .../Simple/ConsoleOutLoggerFactoryAdapter.cs | 104 -- .../Logging/Simple/NamespaceDoc.cs | 31 - .../Logging/Simple/NoOpLogger.cs | 731 ------------ .../Simple/NoOpLoggerFactoryAdapter.cs | 102 -- ...Common.Logging.TestUtils.MonoTouch.csproj} | 4 +- .../Logging/ILogTestsBase.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../TestUtil/SerializationTestUtils.cs | 0 .../TestUtil/TraceEventArgs.cs | 0 .../DefaultConfigurationReader.cs} | 112 +- .../Logging/MonoNet/CollectionsUtil.cs | 0 src/Common.Logging/Logging/LogManager.cs | 5 +- 62 files changed, 262 insertions(+), 5226 deletions(-) rename src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln => Common.Logging.MonoTouch.sln (66%) create mode 100644 Common.Logging.MonoTouch.userprefs rename src/{Common.Logging.MonoTouch/Common.Logging.MonoTouch => }/.DS_Store (96%) create mode 100644 src/Common.Logging.MonoTouch/.DS_Store rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/AssemblyInfo.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Common.Logging.MonoTouch.Tests.csproj (94%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/ExceptionsTest.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Info.plist (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Logging/Configuration/ArgUtilsTests.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs (86%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Logging/Factory/AbstractLoggerTests.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Logging/LogManagerTests.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Logging/LoggingExceptionTests.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Logging/MissingCtorFactoryAdapter.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTests.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTestsBase.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Logging/SImple/ConsoleOutLoggerTests.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Main.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/MethodInvokePerformanceTests.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/Settings.bundle/Root.plist (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/StandardsComplianceTest.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/StopWatch.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch => }/Common.Logging.MonoTouch.Tests/UnitTestAppDelegate.cs (100%) create mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.userprefs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyDoc.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyInfo.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/LogManager.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/ArgUtils.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/LogSetting.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/NamespaceDoc.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationException.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationSectionHandler.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/CoverageExcludeAttribute.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractCachingLoggerFactoryAdapter.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractLogger.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/NamespaceDoc.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/FormatMessageHandler.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/IConfigurationReader.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILog.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILoggerFactoryAdapter.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogLevel.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogManager.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/NamespaceDoc.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLogger.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLogger.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NamespaceDoc.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLogger.cs delete mode 100644 src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLoggerFactoryAdapter.cs rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Common.Logging.TestUtlis.MonoTouch.csproj => Common.Logging.TestUtils.MonoTouch/Common.Logging.TestUtils.MonoTouch.csproj} (93%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch => Common.Logging.TestUtils.MonoTouch}/Logging/ILogTestsBase.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch => Common.Logging.TestUtils.MonoTouch}/Properties/AssemblyInfo.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch => Common.Logging.TestUtils.MonoTouch}/TestUtil/SerializationTestUtils.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch => Common.Logging.TestUtils.MonoTouch}/TestUtil/TraceEventArgs.cs (100%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs => Logging/Configuration/DefaultConfigurationReader.cs} (93%) rename src/Common.Logging.MonoTouch/{Common.Logging.MonoTouch/Common.Logging.MonoTouch => }/Logging/MonoNet/CollectionsUtil.cs (100%) diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln b/Common.Logging.MonoTouch.sln similarity index 66% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln rename to Common.Logging.MonoTouch.sln index c8eef57..f726733 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.sln +++ b/Common.Logging.MonoTouch.sln @@ -1,11 +1,11 @@  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.MonoTouch", "Common.Logging.MonoTouch\Common.Logging.MonoTouch.csproj", "{DD9F81C2-BA9A-4212-9249-2300C62AFF6F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.MonoTouch", "src\Common.Logging.MonoTouch\Common.Logging.MonoTouch.csproj", "{C5FED159-541C-4245-95CA-661C4E29A2DD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.MonoTouch.Tests", "Common.Logging.MonoTouch.Tests\Common.Logging.MonoTouch.Tests.csproj", "{04F451AA-0CEE-4971-AC7E-9D401114F1E2}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.TestUtils.MonoTouch", "src\Common.Logging.MonoTouch\Common.Logging.TestUtils.MonoTouch\Common.Logging.TestUtils.MonoTouch.csproj", "{B928FD65-4E80-4F9D-96D0-830EDB3092DB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.TestUtlis.MonoTouch", "Common.Logging.TestUtlis.MonoTouch\Common.Logging.TestUtlis.MonoTouch.csproj", "{B928FD65-4E80-4F9D-96D0-830EDB3092DB}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Logging.MonoTouch.Tests", "src\Common.Logging.MonoTouch\Common.Logging.MonoTouch.Tests\Common.Logging.MonoTouch.Tests.csproj", "{04F451AA-0CEE-4971-AC7E-9D401114F1E2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,12 +51,24 @@ Global {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|iPhone.Build.0 = Release|Any CPU {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU {B928FD65-4E80-4F9D-96D0-830EDB3092DB}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DD9F81C2-BA9A-4212-9249-2300C62AFF6F}.Release|Any CPU.Build.0 = Release|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.AppStore|iPhone.ActiveCfg = Debug|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.AppStore|iPhone.Build.0 = Debug|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Debug|iPhone.Build.0 = Debug|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Release|Any CPU.Build.0 = Release|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Release|iPhone.ActiveCfg = Release|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Release|iPhone.Build.0 = Release|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {C5FED159-541C-4245-95CA-661C4E29A2DD}.Release|iPhoneSimulator.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = Common.Logging.MonoTouch\Common.Logging.MonoTouch.csproj + StartupItem = src\Common.Logging.MonoTouch\Common.Logging.MonoTouch.csproj EndGlobalSection EndGlobal diff --git a/Common.Logging.MonoTouch.userprefs b/Common.Logging.MonoTouch.userprefs new file mode 100644 index 0000000..b7be76a --- /dev/null +++ b/Common.Logging.MonoTouch.userprefs @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/.DS_Store b/src/.DS_Store similarity index 96% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/.DS_Store rename to src/.DS_Store index 833f29edcb67c4b91dad89b81a8f7cb25fdc1353..7fbaf2e70790b3ab7d191e3eb3d357219c60fecb 100644 GIT binary patch delta 53 zcmZoMXffE}&B(ZJvJYc2mw0uxp@EKqiLu4xU5qlU)it$s^^H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 - - {DD9F81C2-BA9A-4212-9249-2300C62AFF6F} + + {C5FED159-541C-4245-95CA-661C4E29A2DD} Common.Logging.MonoTouch - + {B928FD65-4E80-4F9D-96D0-830EDB3092DB} - Common.Logging.TestUtlis.MonoTouch + Common.Logging.TestUtils.MonoTouch \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/ExceptionsTest.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/ExceptionsTest.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/ExceptionsTest.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/ExceptionsTest.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Info.plist b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Info.plist similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Info.plist rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Info.plist diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/ArgUtilsTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/ArgUtilsTests.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/ArgUtilsTests.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/ArgUtilsTests.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs similarity index 86% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs index 3810209..e36b8e7 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Configuration/MonoTouchConfigurationReaderTests.cs @@ -1,5 +1,5 @@ -#region License - +#region License + /* * Copyright 2002-2009 the original author or authors. * @@ -14,25 +14,25 @@ * 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.Collections.Specialized; -using NUnit.Framework; -using Common.Logging.Simple; -namespace Common.Logging.Configuration -{ - /// - /// - /// Erich Eichinger - [TestFixture] - public class MonoTouchConfigurationReaderTests - { - [Test] - public void ReadsAppConfig() - { - Assert.IsNotNull(((ConsoleOutLoggerFactoryAdapter)new MonoTouchConfigurationReader().GetSection("Settings.bundle/Common.Logging.plist"))); - } - } + */ + +#endregion + +using System.Collections.Specialized; +using NUnit.Framework; +using Common.Logging.Simple; +namespace Common.Logging.Configuration +{ + /// + /// + /// Erich Eichinger + [TestFixture] + public class MonoTouchConfigurationReaderTests + { + [Test] + public void ReadsAppConfig() + { + Assert.IsNotNull(((ConsoleOutLoggerFactoryAdapter)new DefaultConfigurationReader().GetSection("Settings.bundle/Common.Logging.plist"))); + } + } } \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Factory/AbstractLoggerTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Factory/AbstractLoggerTests.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Factory/AbstractLoggerTests.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/Factory/AbstractLoggerTests.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LogManagerTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LogManagerTests.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LogManagerTests.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LogManagerTests.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LoggingExceptionTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LoggingExceptionTests.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LoggingExceptionTests.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/LoggingExceptionTests.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/MissingCtorFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/MissingCtorFactoryAdapter.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/MissingCtorFactoryAdapter.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/MissingCtorFactoryAdapter.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTests.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTests.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTests.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTestsBase.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTestsBase.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTestsBase.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/AbstractSimpleLoggerTestsBase.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/ConsoleOutLoggerTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/ConsoleOutLoggerTests.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/ConsoleOutLoggerTests.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Logging/SImple/ConsoleOutLoggerTests.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Main.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Main.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Main.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Main.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/MethodInvokePerformanceTests.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/MethodInvokePerformanceTests.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/MethodInvokePerformanceTests.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/MethodInvokePerformanceTests.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Common.Logging.plist diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Root.plist b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Root.plist similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Root.plist rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/Settings.bundle/Root.plist diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StandardsComplianceTest.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StandardsComplianceTest.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StandardsComplianceTest.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StandardsComplianceTest.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StopWatch.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StopWatch.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StopWatch.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/StopWatch.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/UnitTestAppDelegate.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/UnitTestAppDelegate.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/UnitTestAppDelegate.cs rename to src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.Tests/UnitTestAppDelegate.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj new file mode 100644 index 0000000..7e42c45 --- /dev/null +++ b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj @@ -0,0 +1,135 @@ + + + + Debug + AnyCPU + 10.0.0 + 2.0 + {C5FED159-541C-4245-95CA-661C4E29A2DD} + {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Common.Logging.MonoTouch + Resources + Common.Logging.MonoTouch + + + true + full + false + bin\Debug + DEBUG;MONOTOUCH; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + false + + + + + + + + + + + + + + + AssemblyDoc.cs + + + AssemblyInfo.cs + + + CoverageExcludeAttribute.cs + + + NamespaceDoc_Introduction.cs + + + Logging\ConfigurationException.cs + + + Logging\FormatMessageHandler.cs + + + Logging\IConfigurationReader.cs + + + Logging\ILog.cs + + + Logging\ILoggerFactoryAdapter.cs + + + Logging\LogLevel.cs + + + Logging\LogManager.cs + + + Logging\NamespaceDoc.cs + + + Logging\Configuration\ArgUtils.cs + + + Logging\Configuration\LogSetting.cs + + + Logging\Configuration\NamespaceDoc.cs + + + Logging\Factory\AbstractCachingLoggerFactoryAdapter.cs + + + Logging\Factory\AbstractLogger.cs + + + Logging\Factory\NamespaceDoc.cs + + + Logging\Simple\AbstractSimpleLogger.cs + + + Logging\Simple\AbstractSimpleLoggerFactoryAdapter.cs + + + Logging\Simple\CapturingLogger.cs + + + Logging\Simple\CapturingLoggerEvent.cs + + + Logging\Simple\CapturingLoggerFactoryAdapter.cs + + + Logging\Simple\ConsoleOutLogger.cs + + + Logging\Simple\ConsoleOutLoggerFactoryAdapter.cs + + + Logging\Simple\ExceptionFormatter.cs + + + Logging\Simple\NamespaceDoc.cs + + + Logging\Simple\NoOpLogger.cs + + + Logging\Simple\NoOpLoggerFactoryAdapter.cs + + + + + \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.userprefs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.userprefs deleted file mode 100644 index 6012b78..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.userprefs +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyDoc.cs deleted file mode 100644 index 12ad8f6..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyDoc.cs +++ /dev/null @@ -1,31 +0,0 @@ -#region License - -/* - * Copyright 2002-2009 the original author or authors. - * - * 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 Common.Logging; - -/// -/// This assembly contains the core functionality of the Common.Logging framework. -/// In particular, checkout and for usage information. -/// -[CoverageExclude] -internal static class AssemblyDoc -{ - // serves as assembly summary for NDoc3 (http://ndoc3.sourceforge.net) -} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyInfo.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyInfo.cs deleted file mode 100644 index 6a6d886..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/AssemblyInfo.cs +++ /dev/null @@ -1,5 +0,0 @@ -using System.Reflection; -using System.Security; - -[assembly: AssemblyProduct("Common Logging Framework")] -[assembly: SecurityTransparent] \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj deleted file mode 100644 index 7f9b8a8..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch.csproj +++ /dev/null @@ -1,84 +0,0 @@ - - - - Debug - AnyCPU - 10.0.0 - 2.0 - {DD9F81C2-BA9A-4212-9249-2300C62AFF6F} - {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Library - Common.Logging.MonoTouch - Resources - Common.Logging.MonoTouch - - - True - full - False - bin\Debug - DEBUG; - prompt - 4 - False - - - none - True - bin\Release - prompt - 4 - False - - - - - - - - - - - - - - - - - - - - - - - - - - - ILoggerFactoryAdapter.cs - - - - - - CommonAssemblyInfo.cs - - - - - Code - - - - - - Code - - - - - - - - - \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/LogManager.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/LogManager.cs deleted file mode 100644 index 2f3b306..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/LogManager.cs +++ /dev/null @@ -1,333 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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.Configuration; -using System.Diagnostics; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Security; -using System.Security.Permissions; -using Common.Logging.Simple; -using Common.Logging.Configuration; - -namespace Common.Logging -{ - /// - /// Use the LogManager's or - /// methods to obtain instances for logging. - /// - /// - /// For configuring the underlying log system using application configuration, see the example - /// at . - /// For configuring programmatically, see the example section below. - /// - /// - /// The example below shows the typical use of LogManager to obtain a reference to a logger - /// and log an exception: - /// - /// - /// ILog log = LogManager.GetLogger(this.GetType()); - /// ... - /// try - /// { - /// /* .... */ - /// } - /// catch(Exception ex) - /// { - /// log.ErrorFormat("Hi {0}", ex, "dude"); - /// } - /// - /// - /// The example below shows programmatic configuration of the underlying log system: - /// - /// - /// // create properties - /// NameValueCollection properties = new NameValueCollection(); - /// properties["showDateTime"] = "true"; - /// - /// // set Adapter - /// Common.Logging.LogManager.Adapter = new - /// Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(properties); - /// - /// - /// - /// - /// - /// - /// - /// Gilles Bayon - public static class LogManager - { - /// - /// The name of the default configuration section to read settings from. - /// - /// - /// You can always change the source of your configuration settings by setting another instance - /// on . - /// - public static readonly string COMMON_LOGGING_SECTION = "common/logging"; - - private static IConfigurationReader _configurationReader; - private static ILoggerFactoryAdapter _adapter; - private static readonly object _loadLock = new object(); - - /// - /// Performs static 1-time init of LogManager by calling - /// - static LogManager() - { - Reset(); - } - - /// - /// Reset the infrastructure to its default settings. This means, that configuration settings - /// will be re-read from section <common/logging> of your app.config. - /// - /// - /// This is mainly used for unit testing, you wouldn't normally use this in your applications.
- /// Note: instances already handed out from this LogManager are not(!) affected. - /// Resetting LogManager only affects new instances being handed out. - ///
- public static void Reset() - { - Reset(new DefaultConfigurationReader()); - } - - /// - /// Reset the infrastructure to its default settings. This means, that configuration settings - /// will be re-read from section <common/logging> of your app.config. - /// - /// - /// This is mainly used for unit testing, you wouldn't normally use this in your applications.
- /// Note: instances already handed out from this LogManager are not(!) affected. - /// Resetting LogManager only affects new instances being handed out. - ///
- /// - /// the instance to obtain settings for - /// re-initializing the LogManager. - /// - public static void Reset(IConfigurationReader reader) - { - lock (_loadLock) - { - if (reader == null) - { - throw new ArgumentNullException("reader"); - } - _configurationReader = reader; - _adapter = null; - } - } - - /// - /// Gets the configuration reader used to initialize the LogManager. - /// - /// Primarily used for testing purposes but maybe useful to obtain configuration - /// information from some place other than the .NET application configuration file. - /// The configuration reader. - public static IConfigurationReader ConfigurationReader - { - get - { - return _configurationReader; - } - } - - /// - /// Gets or sets the adapter. - /// - /// The adapter. - public static ILoggerFactoryAdapter Adapter - { - get - { - if (_adapter == null) - { - lock (_loadLock) - { - if (_adapter == null) - { - _adapter = BuildLoggerFactoryAdapter(); - } - } - } - return _adapter; - } - set - { - if (value == null) - { - throw new ArgumentNullException("Adapter"); - } - - lock (_loadLock) - { - _adapter = value; - } - } - } - - /// - /// Gets the logger by calling - /// on the currently configured using the type of the calling class. - /// - /// - /// This method needs to inspect the in order to determine the calling - /// class. This of course comes with a performance penalty, thus you shouldn't call it too - /// often in your application. - /// - /// - /// the logger instance obtained from the current - [MethodImpl(MethodImplOptions.NoInlining)] - public static ILog GetCurrentClassLogger() - { - StackFrame frame = new StackFrame(1, false); - ILoggerFactoryAdapter adapter = Adapter; - MethodBase method = frame.GetMethod(); - Type declaringType = method.DeclaringType; - return adapter.GetLogger(declaringType); - } - - /// - /// Gets the logger by calling - /// on the currently configured using the specified type. - /// - /// the logger instance obtained from the current - public static ILog GetLogger() - { - return Adapter.GetLogger(typeof(T)); - } - - /// - /// Gets the logger by calling - /// on the currently configured using the specified type. - /// - /// The type. - /// the logger instance obtained from the current - public static ILog GetLogger(Type type) - { - return Adapter.GetLogger(type); - } - - - /// - /// Gets the logger by calling - /// on the currently configured using the specified name. - /// - /// The name. - /// the logger instance obtained from the current - public static ILog GetLogger(string name) - { - return Adapter.GetLogger(name); - } - - - /// - /// Builds the logger factory adapter. - /// - /// a factory adapter instance. Is never null. - private static ILoggerFactoryAdapter BuildLoggerFactoryAdapter() - { - object sectionResult = null; - - ArgUtils.Guard(delegate - { - sectionResult = ConfigurationReader.GetSection(COMMON_LOGGING_SECTION); - } - , "Failed obtaining configuration for Common.Logging from configuration section 'common/logging'."); - - // configuration reader returned - if (sectionResult == null) - { - string message = (ConfigurationReader.GetType() == typeof(DefaultConfigurationReader)) - ? string.Format("no configuration section <{0}> found - suppressing logging output", COMMON_LOGGING_SECTION) - : string.Format("Custom ConfigurationReader '{0}' returned - suppressing logging output", ConfigurationReader.GetType().FullName); - Trace.WriteLine(message); - ILoggerFactoryAdapter defaultFactory = new NoOpLoggerFactoryAdapter(); - return defaultFactory; - } - - // ready to use ILoggerFactoryAdapter? - if (sectionResult is ILoggerFactoryAdapter) - { - Trace.WriteLine(string.Format("Using ILoggerFactoryAdapter returned from custom ConfigurationReader '{0}'", ConfigurationReader.GetType().FullName)); - return (ILoggerFactoryAdapter)sectionResult; - } - - // ensure what's left is a LogSetting instance - ArgUtils.Guard(delegate - { - ArgUtils.AssertIsAssignable("sectionResult", sectionResult.GetType()); - } - , "ConfigurationReader {0} returned unknown settings instance of type {1}" - , ConfigurationReader.GetType().FullName, sectionResult.GetType().FullName); - - ILoggerFactoryAdapter adapter = null; - ArgUtils.Guard(delegate - { - adapter = BuildLoggerFactoryAdapterFromLogSettings((LogSetting)sectionResult); - } - , "Failed creating LoggerFactoryAdapter from settings"); - - return adapter; - } - - /// - /// Builds a instance from the given - /// using . - /// - /// - /// the instance. Is never null - private static ILoggerFactoryAdapter BuildLoggerFactoryAdapterFromLogSettings(LogSetting setting) - { - ArgUtils.AssertNotNull("setting", setting); - // already ensured by LogSetting - // AssertArgIsAssignable("setting.FactoryAdapterType", setting.FactoryAdapterType - // , "Specified FactoryAdapter does not implement {0}. Check implementation of class {1}" - // , typeof(ILoggerFactoryAdapter).FullName - // , setting.FactoryAdapterType.AssemblyQualifiedName); - - ILoggerFactoryAdapter adapter = null; - - ArgUtils.Guard(delegate - { - if (setting.Properties != null - && setting.Properties.Count > 0) - { - object[] args = { setting.Properties }; - - adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType, args); - } - else - { - adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType); - } - } - , "Unable to create instance of type {0}. Possible explanation is lack of zero arg and single arg NameValueCollection constructors" - , setting.FactoryAdapterType.FullName - ); - - // make sure - ArgUtils.AssertNotNull("adapter", adapter, "Activator.CreateInstance() returned "); - return adapter; - } - } -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/ArgUtils.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/ArgUtils.cs deleted file mode 100644 index 52b615e..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/ArgUtils.cs +++ /dev/null @@ -1,316 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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.Diagnostics; - -namespace Common.Logging.Configuration -{ - /// - /// Various utility methods for using during factory and logger instance configuration - /// - /// Erich Eichinger - public static class ArgUtils - { - /// - /// A delegate converting a string representation into the target type - /// - public delegate T ParseHandler(string strValue); - - private static readonly Hashtable s_parsers; - - /// - /// Initialize all members before any of this class' methods can be accessed (avoids beforeFieldInit) - /// - static ArgUtils() - { - s_parsers = new Hashtable(); - RegisterTypeParser(delegate(string s) { return Convert.ToBoolean(s); }); - RegisterTypeParser(delegate(string s) { return Convert.ToInt16(s); }); - RegisterTypeParser(delegate(string s) { return Convert.ToInt32(s); }); - RegisterTypeParser(delegate(string s) { return Convert.ToInt64(s); }); - RegisterTypeParser(delegate(string s) { return Convert.ToSingle(s); }); - RegisterTypeParser(delegate(string s) { return Convert.ToDouble(s); }); - RegisterTypeParser(delegate(string s) { return Convert.ToDecimal(s); }); - } - - /// - /// Adds the parser to the list of known type parsers. - /// - /// - /// .NET intrinsic types are pre-registerd: short, int, long, float, double, decimal, bool - /// - public static void RegisterTypeParser(ParseHandler parser) - { - s_parsers[typeof(T)] = parser; - } - - /// - /// Retrieves the named value from the specified . - /// - /// may be null - /// the value's key - /// if is not null, the value returned by values[name]. null otherwise. - public static string GetValue(NameValueCollection values, string name) - { - return GetValue(values, name, null); - } - - /// - /// Retrieves the named value from the specified . - /// - /// may be null - /// the value's key - /// the default value, if not found - /// if is not null, the value returned by values[name]. null otherwise. - public static string GetValue(NameValueCollection values, string name, string defaultValue) - { - if (values != null) - { - foreach (string key in values.AllKeys) - { - if (string.Compare(name, key, true) == 0) - { - return values[name]; - } - } - } - return defaultValue; - } - - /// - /// Returns the first nonnull, nonempty value among its arguments. - /// - /// - /// Returns null, if the initial list was null or empty. - /// - /// - public static string Coalesce(params string[] values) - { - return Coalesce(delegate(string v) { return !string.IsNullOrEmpty(v); }, values); - } - - /// - /// Returns the first nonnull, nonempty value among its arguments. - /// - /// - /// Also - /// - public static T Coalesce(Predicate predicate, params T[] values) where T : class - { - if (values == null || values.Length == 0) - { - return null; - } - - if (predicate == null) - { - predicate = delegate(T v) { return v != null; }; - } - - for (int i = 0; i < values.Length; i++) - { - T val = values[i]; - if (predicate(val)) - { - return val; - } - } - return null; - } - - /// - /// Tries parsing into an enum of the type of . - /// - /// the default value to return if parsing fails - /// the string value to parse - /// the successfully parsed value, otherwise. - public static T TryParseEnum(T defaultValue, string stringValue) where T : struct - { - if (!typeof(T).IsEnum) - { - throw new ArgumentException(string.Format("Type '{0}' is not an enum type", typeof(T).FullName)); - } - - T result = defaultValue; - if (string.IsNullOrEmpty(stringValue)) - { - return defaultValue; - } - try - { - result = (T)Enum.Parse(typeof(T), stringValue, true); - } - catch - { - Console.Error.WriteLine(string.Format("WARN: failed converting value '{0}' to enum type '{1}'", stringValue, defaultValue.GetType().FullName)); - } - return result; - } - - /// - /// Tries parsing into the specified return type. - /// - /// the default value to return if parsing fails - /// the string value to parse - /// the successfully parsed value, otherwise. - public static T TryParse(T defaultValue, string stringValue) - { - T result = defaultValue; - if (string.IsNullOrEmpty(stringValue)) - { - return defaultValue; - } - - ParseHandler parser = s_parsers[typeof(T)] as ParseHandler; - if (parser == null) - { - throw new ArgumentException(string.Format("There is no parser registered for type {0}", typeof(T).FullName)); - } - - try - { - result = parser(stringValue); - } - catch - { - Console.Error.WriteLine(string.Format("WARN: failed converting value '{0}' to type '{1}' - returning default '{2}'", stringValue, typeof(T).FullName, result)); - } - return result; - } - - /// - /// Throws a if is null. - /// - public static T AssertNotNull(string paramName, T val) where T : class - { - if (ReferenceEquals(val, null)) - { - throw new ArgumentNullException(paramName); - } - return val; - } - - /// - /// Throws a if is null. - /// - public static T AssertNotNull(string paramName, T val, string messageFormat, params object[] args) where T : class - { - if (ReferenceEquals(val, null)) - { - throw new ArgumentNullException(paramName, string.Format(messageFormat, args)); - } - return val; - } - - /// - /// Throws a if an object of type is not - /// assignable to type . - /// - public static Type AssertIsAssignable(string paramName, Type valType) - { - return AssertIsAssignable(paramName - , valType - , string.Format("Type '{0}' of parameter '{1}' is not assignable to target type '{2}'" - , valType == null ? "" : valType.AssemblyQualifiedName - , paramName - , typeof(T).AssemblyQualifiedName) - ); - } - - /// - /// Throws a if an object of type is not - /// assignable to type . - /// - public static Type AssertIsAssignable(string paramName, Type valType, string messageFormat, params object[] args) - { - if (valType == null) - { - throw new ArgumentNullException("valType"); - } - - if (!typeof(T).IsAssignableFrom(valType)) - { - throw new ArgumentOutOfRangeException(paramName, valType, string.Format(messageFormat, args)); - } - return valType; - } - - /// - /// An anonymous action delegate with no arguments and no return value. - /// - /// - public delegate void Action(); - - /// - /// Ensures any exception thrown by the given is wrapped with an - /// . - /// - /// - /// If already throws a ConfigurationException, it will not be wrapped. - /// - /// the action to execute - /// the message to be set on the thrown - /// args to be passed to to format the message - public static void Guard(Action action, string messageFormat, params object[] args) - { - Guard(delegate - { - action(); - return 0; - } - , messageFormat, args); - } - - /// - /// An anonymous action delegate with no arguments and no return value. - /// - /// - public delegate T Function(); - - /// - /// Ensures any exception thrown by the given is wrapped with an - /// . - /// - /// - /// If already throws a ConfigurationException, it will not be wrapped. - /// - /// the action to execute - /// the message to be set on the thrown - /// args to be passed to to format the message - public static T Guard(Function function, string messageFormat, params object[] args) - { - try - { - return function(); - } - catch (ConfigurationException) - { - throw; - } - catch (Exception ex) - { - throw new ConfigurationException(string.Format(messageFormat, args), ex); - } - } - } -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/LogSetting.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/LogSetting.cs deleted file mode 100644 index d54a622..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/LogSetting.cs +++ /dev/null @@ -1,77 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 Common.Logging.Configuration -{ - /// - /// Container used to hold configuration information from config file. - /// - /// Gilles Bayon - public class LogSetting - { - #region Fields - - private readonly Type _factoryAdapterType = null; - private readonly NameValueCollection _properties = null; - - #endregion - - /// - /// - /// - /// - /// The type - /// that will be used for creating - /// - /// - /// Additional user supplied properties that are passed to the - /// 's constructor. - /// - public LogSetting(Type factoryAdapterType, NameValueCollection properties) - { - ArgUtils.AssertNotNull("factoryAdapterType", factoryAdapterType); - ArgUtils.AssertIsAssignable("factoryAdapterType", factoryAdapterType - , "Type {0} does not implement {1}", factoryAdapterType.AssemblyQualifiedName, typeof(ILoggerFactoryAdapter).FullName); - - _factoryAdapterType = factoryAdapterType; - _properties = properties; - } - - /// - /// The type that will be used for creating - /// instances. - /// - public Type FactoryAdapterType - { - get { return _factoryAdapterType; } - } - - /// - /// Additional user supplied properties that are passed to the 's constructor. - /// - public NameValueCollection Properties - { - get { return _properties; } - } - } -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/NamespaceDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/NamespaceDoc.cs deleted file mode 100644 index fa66a7e..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/NamespaceDoc.cs +++ /dev/null @@ -1,31 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 - -namespace Common.Logging.Configuration -{ - /// - /// This namespace contains various utility classes. - /// - [CoverageExclude] - internal static class NamespaceDoc - { - // serves as namespace summary for NDoc3 (http://ndoc3.sourceforge.net) - } -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationException.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationException.cs deleted file mode 100644 index 6254b54..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationException.cs +++ /dev/null @@ -1,84 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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.Runtime.Serialization; - -namespace Common.Logging -{ - /// - /// The exception that is thrown when a configuration system error has occurred with Common.Logging - /// - /// Mark Pollack - [Serializable] - public class ConfigurationException : ApplicationException - { - #region Constructor (s) / Destructor - - /// Creates a new instance of the ObjectsException class. - public ConfigurationException() - { - } - - /// - /// Creates a new instance of the ConfigurationException class. with the specified message. - /// - /// - /// A message about the exception. - /// - public ConfigurationException(string message) : base(message) - { - } - - /// - /// Creates a new instance of the ConfigurationException class with the specified message - /// and root cause. - /// - /// - /// A message about the exception. - /// - /// - /// The root exception that is being wrapped. - /// - public ConfigurationException(string message, Exception rootCause) - : base(message, rootCause) - { - } - - /// - /// Creates a new instance of the ConfigurationException class. - /// - /// - /// The - /// that holds the serialized object data about the exception being thrown. - /// - /// - /// The - /// that contains contextual information about the source or destination. - /// - protected ConfigurationException( - SerializationInfo info, StreamingContext context) - : base(info, context) - { - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationSectionHandler.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationSectionHandler.cs deleted file mode 100644 index 81262e5..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ConfigurationSectionHandler.cs +++ /dev/null @@ -1,232 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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.Runtime.CompilerServices; -using System.Xml; -using Common.Logging.Simple; -using Common.Logging.Configuration; - -namespace Common.Logging -{ - /// - /// Used in an application's configuration file (App.Config or Web.Config) to configure the logging subsystem. - /// - /// - /// An example configuration section that writes log messages to the Console using the - /// built-in Console Logger. - /// - /// <configuration> - /// <configSections> - /// <sectionGroup name="common"> - /// <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> - /// </sectionGroup> - /// </configSections> - /// <common> - /// <logging> - /// <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging"> - /// <arg key="showLogName" value="true" /> - /// <arg key="showDataTime" value="true" /> - /// <arg key="level" value="ALL" /> - /// <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" /> - /// </factoryAdapter> - /// </logging> - /// </common> - /// </configuration> - /// - /// - public class ConfigurationSectionHandler : IConfigurationSectionHandler - { - - #region Fields - - private static readonly string LOGFACTORYADAPTER_ELEMENT = "factoryAdapter"; - 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 - - /// - /// Ensure static fields get initialized before any class member - /// can be accessed (avoids beforeFieldInit) - /// - static ConfigurationSectionHandler() - { } - - /// - /// Constructor - /// - public ConfigurationSectionHandler() - { } - - /// - /// Retrieves the of the logger the use by looking at the logFactoryAdapter element - /// of the logging configuration element. - /// - /// - /// - /// A object containing the specified type that implements - /// along with zero or more properties that will be - /// passed to the logger factory adapter's constructor as an . - /// - 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 - { - if (String.Compare(factoryTypeString, "CONSOLE", true) == 0) - { - factoryType = typeof(ConsoleOutLoggerFactoryAdapter); - } - else if (String.Compare(factoryTypeString, "TRACE", true) == 0) - { - factoryType = typeof(TraceLoggerFactoryAdapter); - } - else if (String.Compare(factoryTypeString, "NOOP", true) == 0) - { - factoryType = typeof(NoOpLoggerFactoryAdapter); - } - else - { - 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 = null; - properties = new NameValueCollection(); // defaults to case-insensitive keys - - 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); - } - - /// - /// Verifies that the logFactoryAdapter element appears once in the configuration section. - /// - /// settings of a parent section - atm this must always be null - /// Additional information about the configuration process. - /// The configuration section to apply an XPath query too. - /// - /// A object containing the specified logFactoryAdapter type - /// along with user supplied configuration properties. - /// - public LogSetting Create(LogSetting parent, object configContext, XmlNode section) - { - if (parent != null) - { - throw new ConfigurationException("parent configuration sections are not allowed"); - } - - int logFactoryElementsCount = section.SelectNodes(LOGFACTORYADAPTER_ELEMENT).Count; - - if (logFactoryElementsCount > 1) - { - throw new ConfigurationException("Only one element allowed"); - } - else if (logFactoryElementsCount == 1) - { - return ReadConfiguration(section); - } - else - { - return null; - } - } - - #region IConfigurationSectionHandler Members - - /// - /// Verifies that the logFactoryAdapter element appears once in the configuration section. - /// - /// The parent of the current item. - /// Additional information about the configuration process. - /// The configuration section to apply an XPath query too. - /// - /// A object containing the specified logFactoryAdapter type - /// along with user supplied configuration properties. - /// - object IConfigurationSectionHandler.Create(object parent, object configContext, XmlNode section) - { - return Create(parent as LogSetting, configContext, section); - } - - #endregion - } -} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/CoverageExcludeAttribute.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/CoverageExcludeAttribute.cs deleted file mode 100644 index 60e7650..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/CoverageExcludeAttribute.cs +++ /dev/null @@ -1,32 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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; - -/// -/// Indicates classes or members to be ignored by NCover -/// -/// -/// Note, the name is chosen, because TestDriven.NET uses it as //ea argument to "Test With... Coverage" -/// -/// Erich Eichinger -[AttributeUsage(AttributeTargets.All)] -internal class CoverageExcludeAttribute : Attribute -{} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractCachingLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractCachingLoggerFactoryAdapter.cs deleted file mode 100644 index 6a5fc61..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractCachingLoggerFactoryAdapter.cs +++ /dev/null @@ -1,132 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 Common.Logging.Factory -{ - /// - /// An implementation of that caches loggers handed out by this factory. - /// - /// - /// Implementors just need to override . - /// - /// Erich Eichinger - public abstract class AbstractCachingLoggerFactoryAdapter : ILoggerFactoryAdapter - { - private readonly Hashtable _cachedLoggers; - - /// - /// Creates a new instance, the logger cache being case-sensitive. - /// - protected AbstractCachingLoggerFactoryAdapter():this(true) - {} - - /// - /// Creates a new instance, the logger cache being . - /// - /// - protected AbstractCachingLoggerFactoryAdapter(bool caseSensitiveLoggerCache) - { - _cachedLoggers = (caseSensitiveLoggerCache) - ? new Hashtable() - : CollectionsUtil.CreateCaseInsensitiveHashtable(); - } - - /// - /// Purges all loggers from cache - /// - protected void ClearLoggerCache() - { - lock (_cachedLoggers) - { - _cachedLoggers.Clear(); - } - } - - /// - /// Create the specified named logger instance - /// - /// - /// Derived factories need to implement this method to create the - /// actual logger instance. - /// - protected abstract ILog CreateLogger(string name); - - #region ILoggerFactoryAdapter Members - - /// - /// Get a ILog instance by . - /// - /// Usually the of the current class. - /// - /// An ILog instance either obtained from the internal cache or created by a call to . - /// - public ILog GetLogger(Type type) - { - return GetLoggerInternal(type.FullName); - } - - /// - /// Get a ILog instance by name. - /// - /// Usually a 's Name or FullName property. - /// - /// An ILog instance either obtained from the internal cache or created by a call to . - /// - public ILog GetLogger(string name) - { - return GetLoggerInternal(name); - } - - /// - /// Get or create a ILog instance by name. - /// - /// Usually a 's Name or FullName property. - /// - /// An ILog instance either obtained from the internal cache or created by a call to . - /// - private ILog GetLoggerInternal(string name) - { - ILog log = _cachedLoggers[name] as ILog; - if (log == null) - { - lock (_cachedLoggers) - { - log = _cachedLoggers[name] as ILog; - if (log == null) - { - log = CreateLogger(name); - if (log == null) - { - throw new ArgumentException(string.Format("{0} returned null on creating logger instance for name {1}", this.GetType().FullName, name)); - } - _cachedLoggers.Add(name, log); - } - } - } - return log; - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractLogger.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractLogger.cs deleted file mode 100644 index 012a20b..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/AbstractLogger.cs +++ /dev/null @@ -1,1033 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 FormatMessageCallback = System.Action; - -namespace Common.Logging.Factory -{ - /// - /// Provides base implementation suitable for almost all logger adapters - /// - /// Erich Eichinger - [Serializable] - public abstract class AbstractLogger : ILog - { - #region FormatMessageCallbackFormattedMessage - - /// - /// Format message on demand. - /// - protected class FormatMessageCallbackFormattedMessage - { - private volatile string cachedMessage; - - private readonly IFormatProvider formatProvider; - private readonly FormatMessageCallback formatMessageCallback; - - /// - /// Initializes a new instance of the class. - /// - /// The format message callback. - public FormatMessageCallbackFormattedMessage(FormatMessageCallback formatMessageCallback) - { - this.formatMessageCallback = formatMessageCallback; - } - - /// - /// Initializes a new instance of the class. - /// - /// The format provider. - /// The format message callback. - public FormatMessageCallbackFormattedMessage(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) - { - this.formatProvider = formatProvider; - this.formatMessageCallback = formatMessageCallback; - } - - /// - /// Calls and returns result. - /// - /// - public override string ToString() - { - if (cachedMessage == null && formatMessageCallback != null) - { - formatMessageCallback(FormatMessage); - } - return cachedMessage; - } - - private string FormatMessage(string format, params object[] args) - { - cachedMessage = string.Format(formatProvider, format, args); - return cachedMessage; - } - } - - #endregion - - #region StringFormatFormattedMessage - - /// - /// Format string on demand. - /// - protected class StringFormatFormattedMessage - { - private volatile string cachedMessage; - - private readonly IFormatProvider FormatProvider; - private readonly string Message; - private readonly object[] Args; - - /// - /// Initializes a new instance of the class. - /// - /// The format provider. - /// The message. - /// The args. - public StringFormatFormattedMessage(IFormatProvider formatProvider, string message, params object[] args) - { - FormatProvider = formatProvider; - Message = message; - Args = args; - } - - /// - /// Runs on supplied arguemnts. - /// - /// string - public override string ToString() - { - if (cachedMessage == null && Message != null) - { - cachedMessage = string.Format(FormatProvider, Message, Args); - } - return cachedMessage; - } - } - - #endregion - - /// - /// Represents a method responsible for writing a message to the log system. - /// - protected delegate void WriteHandler(LogLevel level, object message, Exception exception); - - /// - /// Holds the method for writing a message to the log system. - /// - private readonly WriteHandler Write; - - /// - /// Creates a new logger instance using for - /// writing log events to the underlying log system. - /// - /// - protected AbstractLogger() - { - Write = GetWriteHandler(); - if (Write == null) - { - Write = new WriteHandler(WriteInternal); - } - } - - /// - /// Override this method to use a different method than - /// for writing log events to the underlying log system. - /// - /// - /// Usually you don't need to override thise method. The default implementation returns - /// null to indicate that the default handler should be - /// used. - /// - protected virtual WriteHandler GetWriteHandler() - { - return null; - } - - /// - /// Checks if this logger is enabled for the level. - /// - /// - /// Override this in your derived class to comply with the underlying logging system - /// - public abstract bool IsTraceEnabled { get; } - - /// - /// Checks if this logger is enabled for the level. - /// - /// - /// Override this in your derived class to comply with the underlying logging system - /// - public abstract bool IsDebugEnabled { get; } - - /// - /// Checks if this logger is enabled for the level. - /// - /// - /// Override this in your derived class to comply with the underlying logging system - /// - public abstract bool IsInfoEnabled { get; } - - /// - /// Checks if this logger is enabled for the level. - /// - /// - /// Override this in your derived class to comply with the underlying logging system - /// - public abstract bool IsWarnEnabled { get; } - - /// - /// Checks if this logger is enabled for the level. - /// - /// - /// Override this in your derived class to comply with the underlying logging system - /// - public abstract bool IsErrorEnabled { get; } - - /// - /// Checks if this logger is enabled for the level. - /// - /// - /// Override this in your derived class to comply with the underlying logging system - /// - public abstract bool IsFatalEnabled { get; } - - /// - /// Actually sends the message to the underlying log system. - /// - /// the level of this log event. - /// the message to log - /// the exception to log (may be null) - protected abstract void WriteInternal(LogLevel level, object message, Exception exception); - - #region Trace - - /// - /// Log a message object with the level. - /// - /// The message object to log. - public virtual void Trace(object message) - { - if (IsTraceEnabled) - Write(LogLevel.Trace, message, null); - } - - /// - /// Log a message object with the level including - /// the stack trace of the passed - /// as a parameter. - /// - /// The message object to log. - /// The exception to log, including its stack trace. - public virtual void Trace(object message, Exception exception) - { - if (IsTraceEnabled) - Write(LogLevel.Trace, message, exception); - } - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// - public virtual void TraceFormat(IFormatProvider formatProvider, string format, params object[] args) - { - if (IsTraceEnabled) - Write(LogLevel.Trace, new StringFormatFormattedMessage(formatProvider, format, args), null); - } - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// The exception to log. - /// - public virtual void TraceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) - { - if (IsTraceEnabled) - Write(LogLevel.Trace, new StringFormatFormattedMessage(formatProvider, format, args), exception); - } - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// the list of format arguments - public virtual void TraceFormat(string format, params object[] args) - { - if (IsTraceEnabled) - Write(LogLevel.Trace, new StringFormatFormattedMessage(null, format, args), null); - } - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of format arguments - public virtual void TraceFormat(string format, Exception exception, params object[] args) - { - if (IsTraceEnabled) - Write(LogLevel.Trace, new StringFormatFormattedMessage(null, format, args), exception); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - public virtual void Trace(FormatMessageCallback formatMessageCallback) - { - if (IsTraceEnabled) - Write(LogLevel.Trace, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack trace. - public virtual void Trace(FormatMessageCallback formatMessageCallback, Exception exception) - { - if (IsTraceEnabled) - Write(LogLevel.Trace, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - public virtual void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) - { - if (IsTraceEnabled) - Write(LogLevel.Trace, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack trace. - public virtual void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) - { - if (IsTraceEnabled) - Write(LogLevel.Trace, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); - } - - #endregion - - #region Debug - - /// - /// Log a message object with the level. - /// - /// The message object to log. - public virtual void Debug(object message) - { - if (IsDebugEnabled) - Write(LogLevel.Debug, message, null); - } - - /// - /// Log a message object with the level including - /// the stack Debug of the passed - /// as a parameter. - /// - /// The message object to log. - /// The exception to log, including its stack Debug. - public virtual void Debug(object message, Exception exception) - { - if (IsDebugEnabled) - Write(LogLevel.Debug, message, exception); - } - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// - public virtual void DebugFormat(IFormatProvider formatProvider, string format, params object[] args) - { - if (IsDebugEnabled) - Write(LogLevel.Debug, new StringFormatFormattedMessage(formatProvider, format, args), null); - } - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// The exception to log. - /// - public virtual void DebugFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) - { - if (IsDebugEnabled) - Write(LogLevel.Debug, new StringFormatFormattedMessage(formatProvider, format, args), exception); - } - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// the list of format arguments - public virtual void DebugFormat(string format, params object[] args) - { - if (IsDebugEnabled) - Write(LogLevel.Debug, new StringFormatFormattedMessage(null, format, args), null); - } - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of format arguments - public virtual void DebugFormat(string format, Exception exception, params object[] args) - { - if (IsDebugEnabled) - Write(LogLevel.Debug, new StringFormatFormattedMessage(null, format, args), exception); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - public virtual void Debug(FormatMessageCallback formatMessageCallback) - { - if (IsDebugEnabled) - Write(LogLevel.Debug, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Debug. - public virtual void Debug(FormatMessageCallback formatMessageCallback, Exception exception) - { - if (IsDebugEnabled) - Write(LogLevel.Debug, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - public virtual void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) - { - if (IsDebugEnabled) - Write(LogLevel.Debug, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Debug. - public virtual void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) - { - if (IsDebugEnabled) - Write(LogLevel.Debug, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); - } - - #endregion - - #region Info - - /// - /// Log a message object with the level. - /// - /// The message object to log. - public virtual void Info(object message) - { - if (IsInfoEnabled) - Write(LogLevel.Info, message, null); - } - - /// - /// Log a message object with the level including - /// the stack Info of the passed - /// as a parameter. - /// - /// The message object to log. - /// The exception to log, including its stack Info. - public virtual void Info(object message, Exception exception) - { - if (IsInfoEnabled) - Write(LogLevel.Info, message, exception); - } - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// - public virtual void InfoFormat(IFormatProvider formatProvider, string format, params object[] args) - { - if (IsInfoEnabled) - Write(LogLevel.Info, new StringFormatFormattedMessage(formatProvider, format, args), null); - } - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// The exception to log. - /// - public virtual void InfoFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) - { - if (IsInfoEnabled) - Write(LogLevel.Info, new StringFormatFormattedMessage(formatProvider, format, args), exception); - } - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// the list of format arguments - public virtual void InfoFormat(string format, params object[] args) - { - if (IsInfoEnabled) - Write(LogLevel.Info, new StringFormatFormattedMessage(null, format, args), null); - } - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of format arguments - public virtual void InfoFormat(string format, Exception exception, params object[] args) - { - if (IsInfoEnabled) - Write(LogLevel.Info, new StringFormatFormattedMessage(null, format, args), exception); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - public virtual void Info(FormatMessageCallback formatMessageCallback) - { - if (IsInfoEnabled) - Write(LogLevel.Info, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Info. - public virtual void Info(FormatMessageCallback formatMessageCallback, Exception exception) - { - if (IsInfoEnabled) - Write(LogLevel.Info, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - public virtual void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) - { - if (IsInfoEnabled) - Write(LogLevel.Info, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Info. - public virtual void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) - { - if (IsInfoEnabled) - Write(LogLevel.Info, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); - } - - #endregion - - #region Warn - - /// - /// Log a message object with the level. - /// - /// The message object to log. - public virtual void Warn(object message) - { - if (IsWarnEnabled) - Write(LogLevel.Warn, message, null); - } - - /// - /// Log a message object with the level including - /// the stack Warn of the passed - /// as a parameter. - /// - /// The message object to log. - /// The exception to log, including its stack Warn. - public virtual void Warn(object message, Exception exception) - { - if (IsWarnEnabled) - Write(LogLevel.Warn, message, exception); - } - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting Warnrmation. - /// The format of the message object to log. - /// - public virtual void WarnFormat(IFormatProvider formatProvider, string format, params object[] args) - { - if (IsWarnEnabled) - Write(LogLevel.Warn, new StringFormatFormattedMessage(formatProvider, format, args), null); - } - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting Warnrmation. - /// The format of the message object to log. - /// The exception to log. - /// - public virtual void WarnFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) - { - if (IsWarnEnabled) - Write(LogLevel.Warn, new StringFormatFormattedMessage(formatProvider, format, args), exception); - } - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// the list of format arguments - public virtual void WarnFormat(string format, params object[] args) - { - if (IsWarnEnabled) - Write(LogLevel.Warn, new StringFormatFormattedMessage(null, format, args), null); - } - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of format arguments - public virtual void WarnFormat(string format, Exception exception, params object[] args) - { - if (IsWarnEnabled) - Write(LogLevel.Warn, new StringFormatFormattedMessage(null, format, args), exception); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - public virtual void Warn(FormatMessageCallback formatMessageCallback) - { - if (IsWarnEnabled) - Write(LogLevel.Warn, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Warn. - public virtual void Warn(FormatMessageCallback formatMessageCallback, Exception exception) - { - if (IsWarnEnabled) - Write(LogLevel.Warn, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - public virtual void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) - { - if (IsWarnEnabled) - Write(LogLevel.Warn, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Warn. - public virtual void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) - { - if (IsWarnEnabled) - Write(LogLevel.Warn, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); - } - - #endregion - - #region Error - - /// - /// Log a message object with the level. - /// - /// The message object to log. - public virtual void Error(object message) - { - if (IsErrorEnabled) - Write(LogLevel.Error, message, null); - } - - /// - /// Log a message object with the level including - /// the stack Error of the passed - /// as a parameter. - /// - /// The message object to log. - /// The exception to log, including its stack Error. - public virtual void Error(object message, Exception exception) - { - if (IsErrorEnabled) - Write(LogLevel.Error, message, exception); - } - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting Errorrmation. - /// The format of the message object to log. - /// - public virtual void ErrorFormat(IFormatProvider formatProvider, string format, params object[] args) - { - if (IsErrorEnabled) - Write(LogLevel.Error, new StringFormatFormattedMessage(formatProvider, format, args), null); - } - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting Errorrmation. - /// The format of the message object to log. - /// The exception to log. - /// - public virtual void ErrorFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) - { - if (IsErrorEnabled) - Write(LogLevel.Error, new StringFormatFormattedMessage(formatProvider, format, args), exception); - } - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// the list of format arguments - public virtual void ErrorFormat(string format, params object[] args) - { - if (IsErrorEnabled) - Write(LogLevel.Error, new StringFormatFormattedMessage(null, format, args), null); - } - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of format arguments - public virtual void ErrorFormat(string format, Exception exception, params object[] args) - { - if (IsErrorEnabled) - Write(LogLevel.Error, new StringFormatFormattedMessage(null, format, args), exception); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - public virtual void Error(FormatMessageCallback formatMessageCallback) - { - if (IsErrorEnabled) - Write(LogLevel.Error, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Error. - public virtual void Error(FormatMessageCallback formatMessageCallback, Exception exception) - { - if (IsErrorEnabled) - Write(LogLevel.Error, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - public virtual void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) - { - if (IsErrorEnabled) - Write(LogLevel.Error, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Error. - public virtual void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) - { - if (IsErrorEnabled) - Write(LogLevel.Error, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); - } - - #endregion - - #region Fatal - - /// - /// Log a message object with the level. - /// - /// The message object to log. - public virtual void Fatal(object message) - { - if (IsFatalEnabled) - Write(LogLevel.Fatal, message, null); - } - - /// - /// Log a message object with the level including - /// the stack Fatal of the passed - /// as a parameter. - /// - /// The message object to log. - /// The exception to log, including its stack Fatal. - public virtual void Fatal(object message, Exception exception) - { - if (IsFatalEnabled) - Write(LogLevel.Fatal, message, exception); - } - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting Fatalrmation. - /// The format of the message object to log. - /// - public virtual void FatalFormat(IFormatProvider formatProvider, string format, params object[] args) - { - if (IsFatalEnabled) - Write(LogLevel.Fatal, new StringFormatFormattedMessage(formatProvider, format, args), null); - } - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting Fatalrmation. - /// The format of the message object to log. - /// The exception to log. - /// - public virtual void FatalFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) - { - if (IsFatalEnabled) - Write(LogLevel.Fatal, new StringFormatFormattedMessage(formatProvider, format, args), exception); - } - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// the list of format arguments - public virtual void FatalFormat(string format, params object[] args) - { - if (IsFatalEnabled) - Write(LogLevel.Fatal, new StringFormatFormattedMessage(null, format, args), null); - } - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of format arguments - public virtual void FatalFormat(string format, Exception exception, params object[] args) - { - if (IsFatalEnabled) - Write(LogLevel.Fatal, new StringFormatFormattedMessage(null, format, args), exception); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - public virtual void Fatal(FormatMessageCallback formatMessageCallback) - { - if (IsFatalEnabled) - Write(LogLevel.Fatal, new FormatMessageCallbackFormattedMessage(formatMessageCallback), null); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Fatal. - public virtual void Fatal(FormatMessageCallback formatMessageCallback, Exception exception) - { - if (IsFatalEnabled) - Write(LogLevel.Fatal, new FormatMessageCallbackFormattedMessage(formatMessageCallback), exception); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - public virtual void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) - { - if (IsFatalEnabled) - Write(LogLevel.Fatal, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), null); - } - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Fatal. - public virtual void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) - { - if (IsFatalEnabled) - Write(LogLevel.Fatal, new FormatMessageCallbackFormattedMessage(formatProvider, formatMessageCallback), exception); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/NamespaceDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/NamespaceDoc.cs deleted file mode 100644 index 8eef63d..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Factory/NamespaceDoc.cs +++ /dev/null @@ -1,31 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 - -namespace Common.Logging.Factory -{ - /// - /// This namespace contains convenience base classes for implementing your own s. - /// - [CoverageExclude] - internal static class NamespaceDoc - { - // serves as namespace summary for NDoc3 (http://ndoc3.sourceforge.net) - } -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/FormatMessageHandler.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/FormatMessageHandler.cs deleted file mode 100644 index 5f6babc..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/FormatMessageHandler.cs +++ /dev/null @@ -1,32 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 - -namespace Common.Logging -{ - /// - /// The type of method that is passed into e.g. - /// and allows the callback method to "submit" it's message to the underlying output system. - /// - ///the format argument as in - ///the argument list as in - /// - /// Erich Eichinger - public delegate string FormatMessageHandler(string format, params object[] args); -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/IConfigurationReader.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/IConfigurationReader.cs deleted file mode 100644 index 2822a08..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/IConfigurationReader.cs +++ /dev/null @@ -1,49 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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.Configuration; - -namespace Common.Logging -{ - - /// - /// Interface for basic operations to read .NET application configuration information. - /// - /// Provides a simple abstraction to handle BCL API differences between .NET 1.x and 2.0. Also - /// useful for testing scenarios. - /// Mark Pollack - public interface IConfigurationReader - { - /// - /// Parses the configuration section and returns the resulting object. - /// - /// - ///

- /// Primary purpose of this method is to allow us to parse and - /// load configuration sections using the same API regardless - /// of the .NET framework version. - ///

- ///
- /// Name of the configuration section. - /// Object created by a corresponding . - /// - object GetSection(string sectionName); - } -} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILog.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILog.cs deleted file mode 100644 index 6869265..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILog.cs +++ /dev/null @@ -1,649 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 FormatMessageCallback = System.Action; - -namespace Common.Logging -{ - /// - /// A simple logging interface abstracting logging APIs. - /// - /// - /// - /// Implementations should defer calling a message's until the message really needs - /// to be logged to avoid performance penalties. - /// - /// - /// Each log method offers to pass in a instead of the actual message. - /// Using this style has the advantage to defer possibly expensive message argument evaluation and formatting (and formatting arguments!) until the message gets - /// actually logged. If the message is not logged at all (e.g. due to settings), - /// you won't have to pay the peformance penalty of creating the message. - /// - /// - /// - /// The example below demonstrates using callback style for creating the message, where the call to the - /// and the underlying only happens, if level is enabled: - /// - /// Log.Debug( m=>m("result is {0}", random.NextDouble()) ); - /// Log.Debug(delegate(m) { m("result is {0}", random.NextDouble()); }); - /// - /// - /// - /// Mark Pollack - /// Bruno Baia - /// Erich Eichinger - public interface ILog - { - /// - /// Log a message object with the level. - /// - /// The message object to log. - void Trace(object message); - - /// - /// Log a message object with the level including - /// the stack trace of the passed - /// as a parameter. - /// - /// The message object to log. - /// The exception to log, including its stack trace. - void Trace(object message, Exception exception); - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// the list of format arguments - void TraceFormat(string format, params object[] args); - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of format arguments - void TraceFormat(string format, Exception exception, params object[] args); - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// - void TraceFormat(IFormatProvider formatProvider, string format, params object[] args); - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// The exception to log. - /// - void TraceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - void Trace(FormatMessageCallback formatMessageCallback); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack trace. - void Trace(FormatMessageCallback formatMessageCallback, Exception exception); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack trace. - void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); - - /// - /// Log a message object with the level. - /// - /// The message object to log. - void Debug( object message ); - - /// - /// Log a message object with the level including - /// the stack trace of the passed - /// as a parameter. - /// - /// The message object to log. - /// The exception to log, including its stack trace. - void Debug( object message, Exception exception ); - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// the list of format arguments - void DebugFormat(string format, params object[] args); - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of format arguments - void DebugFormat(string format, Exception exception, params object[] args); - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// - void DebugFormat(IFormatProvider formatProvider, string format, params object[] args); - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// The exception to log. - /// - void DebugFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - void Debug(FormatMessageCallback formatMessageCallback); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack trace. - void Debug(FormatMessageCallback formatMessageCallback, Exception exception); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Debug. - void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); - - /// - /// Log a message object with the level. - /// - /// The message object to log. - void Info(object message); - - /// - /// Log a message object with the level including - /// the stack trace of the passed - /// as a parameter. - /// - /// The message object to log. - /// The exception to log, including its stack trace. - void Info(object message, Exception exception); - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// the list of format arguments - void InfoFormat(string format, params object[] args); - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of format arguments - void InfoFormat(string format, Exception exception, params object[] args); - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// - void InfoFormat(IFormatProvider formatProvider, string format, params object[] args); - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// The exception to log. - /// - void InfoFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - void Info(FormatMessageCallback formatMessageCallback); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack trace. - void Info(FormatMessageCallback formatMessageCallback, Exception exception); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Info. - void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); - - /// - /// Log a message object with the level. - /// - /// The message object to log. - void Warn(object message); - - /// - /// Log a message object with the level including - /// the stack trace of the passed - /// as a parameter. - /// - /// The message object to log. - /// The exception to log, including its stack trace. - void Warn(object message, Exception exception); - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// the list of format arguments - void WarnFormat(string format, params object[] args); - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of format arguments - void WarnFormat(string format, Exception exception, params object[] args); - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// - void WarnFormat(IFormatProvider formatProvider, string format, params object[] args); - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// The exception to log. - /// - void WarnFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - void Warn(FormatMessageCallback formatMessageCallback); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack trace. - void Warn(FormatMessageCallback formatMessageCallback, Exception exception); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Warn. - void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); - - /// - /// Log a message object with the level. - /// - /// The message object to log. - void Error( object message ); - - /// - /// Log a message object with the level including - /// the stack trace of the passed - /// as a parameter. - /// - /// The message object to log. - /// The exception to log, including its stack trace. - void Error( object message, Exception exception ); - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// the list of format arguments - void ErrorFormat(string format, params object[] args); - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of format arguments - void ErrorFormat(string format, Exception exception, params object[] args); - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// - void ErrorFormat(IFormatProvider formatProvider, string format, params object[] args); - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// The exception to log. - /// - void ErrorFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - void Error(FormatMessageCallback formatMessageCallback); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack trace. - void Error(FormatMessageCallback formatMessageCallback, Exception exception); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Error. - void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); - - /// - /// Log a message object with the level. - /// - /// The message object to log. - void Fatal( object message ); - - /// - /// Log a message object with the level including - /// the stack trace of the passed - /// as a parameter. - /// - /// The message object to log. - /// The exception to log, including its stack trace. - void Fatal( object message, Exception exception ); - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// the list of format arguments - void FatalFormat(string format, params object[] args); - - /// - /// Log a message with the level. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of format arguments - void FatalFormat(string format, Exception exception, params object[] args); - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// - void FatalFormat(IFormatProvider formatProvider, string format, params object[] args); - - /// - /// Log a message with the level. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// The exception to log. - /// - void FatalFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - void Fatal(FormatMessageCallback formatMessageCallback); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack trace. - void Fatal(FormatMessageCallback formatMessageCallback, Exception exception); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback); - - /// - /// Log a message with the level using a callback to obtain the message - /// - /// - /// Using this method avoids the cost of creating a message and evaluating message arguments - /// that probably won't be logged due to loglevel settings. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Fatal. - void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception); - - /// - /// Checks if this logger is enabled for the level. - /// - bool IsTraceEnabled - { - get; - } - - /// - /// Checks if this logger is enabled for the level. - /// - bool IsDebugEnabled - { - get; - } - - /// - /// Checks if this logger is enabled for the level. - /// - bool IsErrorEnabled - { - get; - } - - /// - /// Checks if this logger is enabled for the level. - /// - bool IsFatalEnabled - { - get; - } - - /// - /// Checks if this logger is enabled for the level. - /// - bool IsInfoEnabled - { - get; - } - - /// - /// Checks if this logger is enabled for the level. - /// - bool IsWarnEnabled - { - get; - } - } -} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILoggerFactoryAdapter.cs deleted file mode 100644 index 524bc52..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/ILoggerFactoryAdapter.cs +++ /dev/null @@ -1,49 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 Common.Logging -{ - /// - /// LoggerFactoryAdapter interface is used internally by LogManager - /// Only developers wishing to write new Common.Logging adapters need to - /// worry about this interface. - /// - /// Gilles Bayon - public interface ILoggerFactoryAdapter - { - - /// - /// Get a ILog instance by type. - /// - /// The type to use for the logger - /// - ILog GetLogger( Type type ); - - /// - /// Get a ILog instance by name. - /// - /// The name of the logger - /// - ILog GetLogger( string name ); - - } -} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogLevel.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogLevel.cs deleted file mode 100644 index f1ad189..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogLevel.cs +++ /dev/null @@ -1,62 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 - -namespace Common.Logging -{ - /// - /// The 7 possible logging levels - /// - /// Gilles Bayon - public enum LogLevel - { - /// - /// All logging levels - /// - All = 0, - /// - /// A trace logging level - /// - Trace = 1, - /// - /// A debug logging level - /// - Debug = 2, - /// - /// A info logging level - /// - Info = 3, - /// - /// A warn logging level - /// - Warn = 4, - /// - /// An error logging level - /// - Error = 5, - /// - /// A fatal logging level - /// - Fatal = 6, - /// - /// Do not log anything. - /// - Off = 7, - } -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogManager.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogManager.cs deleted file mode 100644 index 4ba8d98..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/LogManager.cs +++ /dev/null @@ -1,333 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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.Configuration; -using System.Diagnostics; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Security; -using System.Security.Permissions; -using Common.Logging.Simple; -using Common.Logging.Configuration; - -namespace Common.Logging -{ - /// - /// Use the LogManager's or - /// methods to obtain instances for logging. - /// - /// - /// For configuring the underlying log system using application configuration, see the example - /// at . - /// For configuring programmatically, see the example section below. - /// - /// - /// The example below shows the typical use of LogManager to obtain a reference to a logger - /// and log an exception: - /// - /// - /// ILog log = LogManager.GetLogger(this.GetType()); - /// ... - /// try - /// { - /// /* .... */ - /// } - /// catch(Exception ex) - /// { - /// log.ErrorFormat("Hi {0}", ex, "dude"); - /// } - /// - /// - /// The example below shows programmatic configuration of the underlying log system: - /// - /// - /// // create properties - /// NameValueCollection properties = new NameValueCollection(); - /// properties["showDateTime"] = "true"; - /// - /// // set Adapter - /// Common.Logging.LogManager.Adapter = new - /// Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(properties); - /// - /// - /// - /// - /// - /// - /// - /// Gilles Bayon - public static class LogManager - { - /// - /// The name of the default configuration section to read settings from. - /// - /// - /// You can always change the source of your configuration settings by setting another instance - /// on . - /// - public static readonly string COMMON_LOGGING_SECTION = "Settings.bundle/Common.Logging.plist"; - - private static IConfigurationReader _configurationReader; - private static ILoggerFactoryAdapter _adapter; - private static readonly object _loadLock = new object(); - - /// - /// Performs static 1-time init of LogManager by calling - /// - static LogManager() - { - Reset(); - } - - /// - /// Reset the infrastructure to its default settings. This means, that configuration settings - /// will be re-read from section <common/logging> of your app.config. - /// - /// - /// This is mainly used for unit testing, you wouldn't normally use this in your applications.
- /// Note: instances already handed out from this LogManager are not(!) affected. - /// Resetting LogManager only affects new instances being handed out. - ///
- public static void Reset() - { - Reset(new MonoTouchConfigurationReader()); - } - - /// - /// Reset the infrastructure to its default settings. This means, that configuration settings - /// will be re-read from section <common/logging> of your app.config. - /// - /// - /// This is mainly used for unit testing, you wouldn't normally use this in your applications.
- /// Note: instances already handed out from this LogManager are not(!) affected. - /// Resetting LogManager only affects new instances being handed out. - ///
- /// - /// the instance to obtain settings for - /// re-initializing the LogManager. - /// - public static void Reset(IConfigurationReader reader) - { - lock (_loadLock) - { - if (reader == null) - { - throw new ArgumentNullException("reader"); - } - _configurationReader = reader; - _adapter = null; - } - } - - /// - /// Gets the configuration reader used to initialize the LogManager. - /// - /// Primarily used for testing purposes but maybe useful to obtain configuration - /// information from some place other than the .NET application configuration file. - /// The configuration reader. - public static IConfigurationReader ConfigurationReader - { - get - { - return _configurationReader; - } - } - - /// - /// Gets or sets the adapter. - /// - /// The adapter. - public static ILoggerFactoryAdapter Adapter - { - get - { - if (_adapter == null) - { - lock (_loadLock) - { - if (_adapter == null) - { - _adapter = BuildLoggerFactoryAdapter(); - } - } - } - return _adapter; - } - set - { - if (value == null) - { - throw new ArgumentNullException("Adapter"); - } - - lock (_loadLock) - { - _adapter = value; - } - } - } - - /// - /// Gets the logger by calling - /// on the currently configured using the type of the calling class. - /// - /// - /// This method needs to inspect the in order to determine the calling - /// class. This of course comes with a performance penalty, thus you shouldn't call it too - /// often in your application. - /// - /// - /// the logger instance obtained from the current - [MethodImpl(MethodImplOptions.NoInlining)] - public static ILog GetCurrentClassLogger() - { - StackFrame frame = new StackFrame(1, false); - ILoggerFactoryAdapter adapter = Adapter; - MethodBase method = frame.GetMethod(); - Type declaringType = method.DeclaringType; - return adapter.GetLogger(declaringType); - } - - /// - /// Gets the logger by calling - /// on the currently configured using the specified type. - /// - /// the logger instance obtained from the current - public static ILog GetLogger() - { - return Adapter.GetLogger(typeof(T)); - } - - /// - /// Gets the logger by calling - /// on the currently configured using the specified type. - /// - /// The type. - /// the logger instance obtained from the current - public static ILog GetLogger(Type type) - { - return Adapter.GetLogger(type); - } - - - /// - /// Gets the logger by calling - /// on the currently configured using the specified name. - /// - /// The name. - /// the logger instance obtained from the current - public static ILog GetLogger(string name) - { - return Adapter.GetLogger(name); - } - - - /// - /// Builds the logger factory adapter. - /// - /// a factory adapter instance. Is never null. - private static ILoggerFactoryAdapter BuildLoggerFactoryAdapter() - { - object sectionResult = null; - - ArgUtils.Guard(delegate - { - sectionResult = ConfigurationReader.GetSection(COMMON_LOGGING_SECTION); - } - , "Failed obtaining configuration for Common.Logging from configuration section 'common/logging'."); - - // configuration reader returned - if (sectionResult == null) - { - string message = (ConfigurationReader.GetType() == typeof(MonoTouchConfigurationReader)) - ? string.Format("no configuration plist <{0}> found - suppressing logging output", COMMON_LOGGING_SECTION) - : string.Format("Custom ConfigurationReader '{0}' returned - suppressing logging output", ConfigurationReader.GetType().FullName); - Console.Error.WriteLine(message); - ILoggerFactoryAdapter defaultFactory = new NoOpLoggerFactoryAdapter(); - return defaultFactory; - } - - // ready to use ILoggerFactoryAdapter? - if (sectionResult is ILoggerFactoryAdapter) - { - Console.Error.WriteLine(string.Format("Using ILoggerFactoryAdapter returned from custom ConfigurationReader '{0}'", ConfigurationReader.GetType().FullName)); - return (ILoggerFactoryAdapter)sectionResult; - } - - // ensure what's left is a LogSetting instance - ArgUtils.Guard(delegate - { - ArgUtils.AssertIsAssignable("sectionResult", sectionResult.GetType()); - } - , "ConfigurationReader {0} returned unknown settings instance of type {1}" - , ConfigurationReader.GetType().FullName, sectionResult.GetType().FullName); - - ILoggerFactoryAdapter adapter = null; - ArgUtils.Guard(delegate - { - adapter = BuildLoggerFactoryAdapterFromLogSettings((LogSetting)sectionResult); - } - , "Failed creating LoggerFactoryAdapter from settings"); - - return adapter; - } - - /// - /// Builds a instance from the given - /// using . - /// - /// - /// the instance. Is never null - private static ILoggerFactoryAdapter BuildLoggerFactoryAdapterFromLogSettings(LogSetting setting) - { - ArgUtils.AssertNotNull("setting", setting); - // already ensured by LogSetting - // AssertArgIsAssignable("setting.FactoryAdapterType", setting.FactoryAdapterType - // , "Specified FactoryAdapter does not implement {0}. Check implementation of class {1}" - // , typeof(ILoggerFactoryAdapter).FullName - // , setting.FactoryAdapterType.AssemblyQualifiedName); - - ILoggerFactoryAdapter adapter = null; - - ArgUtils.Guard(delegate - { - if (setting.Properties != null - && setting.Properties.Count > 0) - { - object[] args = { setting.Properties }; - - adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType, args); - } - else - { - adapter = (ILoggerFactoryAdapter)Activator.CreateInstance(setting.FactoryAdapterType); - } - } - , "Unable to create instance of type {0}. Possible explanation is lack of zero arg and single arg NameValueCollection constructors" - , setting.FactoryAdapterType.FullName - ); - - // make sure - ArgUtils.AssertNotNull("adapter", adapter, "Activator.CreateInstance() returned "); - return adapter; - } - } -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/NamespaceDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/NamespaceDoc.cs deleted file mode 100644 index 8548947..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/NamespaceDoc.cs +++ /dev/null @@ -1,31 +0,0 @@ -#region License - -/* - * Copyright 2002-2009 the original author or authors. - * - * 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 - -namespace Common.Logging -{ - /// - /// This namespace contains all core classes making up the Common.Logging framework. - /// - [CoverageExclude] - internal static class NamespaceDoc - { - // serves as namespace summary for NDoc3 (http://ndoc3.sourceforge.net) - } -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLogger.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLogger.cs deleted file mode 100644 index fb541ed..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLogger.cs +++ /dev/null @@ -1,263 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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.Globalization; -using System.Text; -using Common.Logging.Factory; - -namespace Common.Logging.Simple -{ - /// - /// Abstract class providing a standard implementation of simple loggers. - /// - /// Erich Eichinger - [Serializable] - public abstract class AbstractSimpleLogger : AbstractLogger - { - private readonly string _name; - private readonly bool _showLevel; - private readonly bool _showDateTime; - private readonly bool _showLogName; - private LogLevel _currentLogLevel; - private readonly string _dateTimeFormat; - private readonly bool _hasDateTimeFormat; - - #region Properties - - /// - /// The name of the logger. - /// - [CoverageExclude] - public string Name - { - get { return _name; } - } - - /// - /// Include the current log level in the log message. - /// - [CoverageExclude] - public bool ShowLevel - { - get { return _showLevel; } - } - - /// - /// Include the current time in the log message. - /// - [CoverageExclude] - public bool ShowDateTime - { - get { return _showDateTime; } - } - - /// - /// Include the instance name in the log message. - /// - [CoverageExclude] - public bool ShowLogName - { - get { return _showLogName; } - } - - /// - /// The current logging threshold. Messages recieved that are beneath this threshold will not be logged. - /// - [CoverageExclude] - public LogLevel CurrentLogLevel - { - get { return _currentLogLevel; } - set { _currentLogLevel = value; } - } - - /// - /// The date and time format to use in the log message. - /// - [CoverageExclude] - public string DateTimeFormat - { - get { return _dateTimeFormat; } - } - - /// - /// Determines Whether is set. - /// - [CoverageExclude] - public bool HasDateTimeFormat - { - get { return _hasDateTimeFormat; } - } - - - #endregion - - /// - /// Creates and initializes a the simple logger. - /// - /// The name, usually type name of the calling class, of the logger. - /// The current logging threshold. Messages recieved that are beneath this threshold will not be logged. - /// Include level in the log message. - /// Include the current time in the log message. - /// Include the instance name in the log message. - /// The date and time format to use in the log message. - public AbstractSimpleLogger(string logName, LogLevel logLevel, bool showlevel - , bool showDateTime, bool showLogName, string dateTimeFormat) - { - _name = logName; - _currentLogLevel = logLevel; - _showLevel = showlevel; - _showDateTime = showDateTime; - _showLogName = showLogName; - _dateTimeFormat = dateTimeFormat; - _hasDateTimeFormat = (!string.IsNullOrEmpty(_dateTimeFormat)); - } - - /// - /// Appends the formatted message to the specified . - /// - /// the that receíves the formatted message. - /// - /// - /// - protected virtual void FormatOutput(StringBuilder stringBuilder, LogLevel level, object message, Exception e) - { - if (stringBuilder == null) - { - throw new ArgumentNullException("stringBuilder"); - } - - // Append date-time if so configured - if (_showDateTime) - { - if (_hasDateTimeFormat) - { - stringBuilder.Append(DateTime.Now.ToString(_dateTimeFormat, CultureInfo.InvariantCulture)); - } - else - { - stringBuilder.Append(DateTime.Now); - } - - stringBuilder.Append(" "); - } - - if (_showLevel) - { - // Append a readable representation of the log level - stringBuilder.Append(("[" + level.ToString().ToUpper() + "]").PadRight(8)); - } - - // Append the name of the log instance if so configured - if (_showLogName) - { - stringBuilder.Append(_name).Append(" - "); - } - - // Append the message - stringBuilder.Append(message); - - // Append stack trace if not null - if (e != null) - { - stringBuilder.Append(Environment.NewLine).Append(e.ToString()); - } - } - - /// - /// Determines if the given log level is currently enabled. - /// - /// - /// - protected virtual bool IsLevelEnabled(LogLevel level) - { - int iLevel = (int)level; - int iCurrentLogLevel = (int)_currentLogLevel; - - // return iLevel.CompareTo(iCurrentLogLevel); better ??? - return (iLevel >= iCurrentLogLevel); - } - - #region ILog Members - - /// - /// Returns if the current is greater than or - /// equal to . If it is, all messages will be sent to . - /// - public override bool IsTraceEnabled - { - get { return IsLevelEnabled(LogLevel.Trace); } - } - - /// - /// Returns if the current is greater than or - /// equal to . If it is, all messages will be sent to . - /// - public override bool IsDebugEnabled - { - get { return IsLevelEnabled(LogLevel.Debug); } - } - - /// - /// Returns if the current is greater than or - /// equal to . If it is, only messages with a of - /// , , , and - /// will be sent to . - /// - public override bool IsInfoEnabled - { - get { return IsLevelEnabled(LogLevel.Info); } - } - - - /// - /// Returns if the current is greater than or - /// equal to . If it is, only messages with a of - /// , , and - /// will be sent to . - /// - public override bool IsWarnEnabled - { - get { return IsLevelEnabled(LogLevel.Warn); } - } - - /// - /// Returns if the current is greater than or - /// equal to . If it is, only messages with a of - /// and will be sent to . - /// - public override bool IsErrorEnabled - { - get { return IsLevelEnabled(LogLevel.Error); } - } - - /// - /// Returns if the current is greater than or - /// equal to . If it is, only messages with a of - /// will be sent to . - /// - public override bool IsFatalEnabled - { - get { return IsLevelEnabled(LogLevel.Fatal); } - } - - #endregion - } -} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs deleted file mode 100644 index ae9aea1..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/AbstractSimpleLoggerFactoryAdapter.cs +++ /dev/null @@ -1,191 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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.Collections.Specialized; -using Common.Logging.Factory; -using Common.Logging.Configuration; - -namespace Common.Logging.Simple -{ - /// - /// Base factory implementation for creating simple instances. - /// - /// Default settings are LogLevel.All, showDateTime = true, showLogName = true, and no DateTimeFormat. - /// The keys in the NameValueCollection to configure this adapter are the following - /// - /// level - /// showDateTime - /// showLogName - /// dateTimeFormat - /// - /// - /// Here is an example how to implement your own logging adapter: - /// - /// public class ConsoleOutLogger : AbstractSimpleLogger - /// { - /// public ConsoleOutLogger(string logName, LogLevel logLevel, bool showLevel, bool showDateTime, - /// bool showLogName, string dateTimeFormat) - /// : base(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat) - /// { - /// } - /// - /// protected override void WriteInternal(LogLevel level, object message, Exception e) - /// { - /// // Use a StringBuilder for better performance - /// StringBuilder sb = new StringBuilder(); - /// FormatOutput(sb, level, message, e); - /// - /// // Print to the appropriate destination - /// Console.Out.WriteLine(sb.ToString()); - /// } - /// } - /// - /// public class ConsoleOutLoggerFactoryAdapter : AbstractSimpleLoggerFactoryAdapter - /// { - /// public ConsoleOutLoggerFactoryAdapter(NameValueCollection properties) - /// : base(properties) - /// { } - /// - /// protected override ILog CreateLogger(string name, LogLevel level, bool showLevel, bool - /// showDateTime, bool showLogName, string dateTimeFormat) - /// { - /// ILog log = new ConsoleOutLogger(name, level, showLevel, showDateTime, showLogName, - /// dateTimeFormat); - /// return log; - /// } - /// } - /// - /// - /// - /// - /// - /// Gilles Bayon - /// Mark Pollack - /// Erich Eichinger - public abstract class AbstractSimpleLoggerFactoryAdapter : AbstractCachingLoggerFactoryAdapter - { - private LogLevel _level; - private bool _showLevel; - private bool _showDateTime; - private bool _showLogName; - private string _dateTimeFormat; - - /// - /// The default to use when creating new instances. - /// - [CoverageExclude] - public LogLevel Level - { - get { return _level; } - set { _level = value; } - } - - /// - /// The default setting to use when creating new instances. - /// - [CoverageExclude] - public bool ShowLevel - { - get { return _showLevel; } - set { _showLevel = value; } - } - - /// - /// The default setting to use when creating new instances. - /// - [CoverageExclude] - public bool ShowDateTime - { - get { return _showDateTime; } - set { _showDateTime = value; } - } - - /// - /// The default setting to use when creating new instances. - /// - [CoverageExclude] - public bool ShowLogName - { - get { return _showLogName; } - set { _showLogName = value; } - } - - /// - /// The default setting to use when creating new instances. - /// - [CoverageExclude] - public string DateTimeFormat - { - get { return _dateTimeFormat; } - set { _dateTimeFormat = value; } - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// Looks for level, showDateTime, showLogName, dateTimeFormat items from - /// for use when the GetLogger methods are called. - /// for more information on how to use the - /// standard .NET application configuraiton file (App.config/Web.config) - /// to configure this adapter. - /// - /// The name value collection, typically specified by the user in - /// a configuration section named common/logging. - protected AbstractSimpleLoggerFactoryAdapter(NameValueCollection properties) - :this( - ArgUtils.TryParseEnum(LogLevel.All, ArgUtils.GetValue(properties, "level")), - ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showDateTime")), - ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showLogName")), - ArgUtils.TryParse(true, ArgUtils.GetValue(properties, "showLevel")), - ArgUtils.GetValue(properties, "dateTimeFormat", string.Empty) - ) - {} - - /// - /// Initializes a new instance of the class with - /// default settings for the loggers created by this factory. - /// - protected AbstractSimpleLoggerFactoryAdapter(LogLevel level, bool showDateTime, bool showLogName, bool showLevel, string dateTimeFormat) - :base(true) - { - _level = level; - _showDateTime = showDateTime; - _showLogName = showLogName; - _showLevel = showLevel; - _dateTimeFormat = dateTimeFormat ?? string.Empty; - } - - /// - /// Create the specified logger instance - /// - protected override ILog CreateLogger(string name) - { - return CreateLogger(name, _level, _showLevel, _showDateTime, _showLogName, _dateTimeFormat); - } - - /// - /// Derived factories need to implement this method to create the - /// actual logger instance. - /// - /// a new logger instance. Must never be null! - protected abstract ILog CreateLogger(string name, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat); - } -} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLogger.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLogger.cs deleted file mode 100644 index 735e35f..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLogger.cs +++ /dev/null @@ -1,64 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 Common.Logging.Simple -{ - /// - /// Sends log messages to . - /// - /// Gilles Bayon - [Serializable] - public class ConsoleOutLogger : AbstractSimpleLogger - { - /// - /// Creates and initializes a logger that writes messages to . - /// - /// The name, usually type name of the calling class, of the logger. - /// The current logging threshold. Messages recieved that are beneath this threshold will not be logged. - /// Include the current log level in the log message. - /// Include the current time in the log message. - /// Include the instance name in the log message. - /// The date and time format to use in the log message. - public ConsoleOutLogger(string logName, LogLevel logLevel, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) - : base(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat) - { - } - - /// - /// Do the actual logging by constructing the log message using a then - /// sending the output to . - /// - /// The of the message. - /// The log message. - /// An optional associated with the message. - protected override void WriteInternal(LogLevel level, object message, Exception e) - { - // Use a StringBuilder for better performance - StringBuilder sb = new StringBuilder(); - FormatOutput(sb, level, message, e); - - // Print to the appropriate destination - Console.Out.WriteLine(sb.ToString()); - } - } -} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs deleted file mode 100644 index 1719a7d..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/ConsoleOutLoggerFactoryAdapter.cs +++ /dev/null @@ -1,104 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 Common.Logging.Simple -{ - /// - /// Factory for creating instances that write data to . - /// - /// - /// - /// Below is an example how to configure this adapter: - /// - /// <configuration> - /// - /// <configSections> - /// <sectionGroup name="common"> - /// <section name="logging" - /// type="Common.Logging.ConfigurationSectionHandler, Common.Logging" - /// requirePermission="false" /> - /// </sectionGroup> - /// </configSections> - /// - /// <common> - /// <logging> - /// <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging"> - /// <arg key="level" value="ALL" /> - /// </factoryAdapter> - /// </logging> - /// </common> - /// - /// </configuration> - /// - /// - /// - /// - /// - /// - /// Gilles Bayon - /// Mark Pollack - /// Erich Eichinger - public class ConsoleOutLoggerFactoryAdapter : AbstractSimpleLoggerFactoryAdapter - { - /// - /// Initializes a new instance of the class using default - /// settings. - /// - public ConsoleOutLoggerFactoryAdapter() - : base(null) - { } - - /// - /// Initializes a new instance of the class. - /// - /// - /// Looks for level, showDateTime, showLogName, dateTimeFormat items from - /// for use when the GetLogger methods are called. - /// for more information on how to use the - /// standard .NET application configuraiton file (App.config/Web.config) - /// to configure this adapter. - /// - /// The name value collection, typically specified by the user in - /// a configuration section named common/logging. - public ConsoleOutLoggerFactoryAdapter(NameValueCollection properties) - : base(properties) - { } - - /// - /// Initializes a new instance of the class with - /// default settings for the loggers created by this factory. - /// - public ConsoleOutLoggerFactoryAdapter(LogLevel level, bool showDateTime, bool showLogName, bool showLevel, string dateTimeFormat) - : base(level, showDateTime, showLogName, showLevel, dateTimeFormat) - { } - - /// - /// Creates a new instance. - /// - protected override ILog CreateLogger(string name, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat) - { - ILog log = new ConsoleOutLogger(name, level, showLevel, showDateTime, showLogName, dateTimeFormat); - return log; - } - } -} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NamespaceDoc.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NamespaceDoc.cs deleted file mode 100644 index 99ff197..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NamespaceDoc.cs +++ /dev/null @@ -1,31 +0,0 @@ -#region License - -/* - * Copyright 2002-2009 the original author or authors. - * - * 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 - -namespace Common.Logging.Simple -{ - /// - /// This namespace contains all core classes making up the Common.Logging framework. - /// - [CoverageExclude] - internal static class NamespaceDoc - { - // serves as namespace summary for NDoc3 (http://ndoc3.sourceforge.net) - } -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLogger.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLogger.cs deleted file mode 100644 index 3d5f287..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLogger.cs +++ /dev/null @@ -1,731 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 FormatMessageCallback = System.Action; - -namespace Common.Logging.Simple -{ - /// - /// Silently ignores all log messages. - /// - /// Gilles Bayon - /// Erich Eichinger - [Serializable] - [CoverageExclude] - public sealed class NoOpLogger : ILog - { - #region IsXXXEnabled - - /// - /// Always returns . - /// - public bool IsTraceEnabled - { - get { return false; } - } - - /// - /// Always returns . - /// - public bool IsDebugEnabled - { - get { return false; } - } - - /// - /// Always returns . - /// - public bool IsInfoEnabled - { - get { return false; } - } - - /// - /// Always returns . - /// - public bool IsWarnEnabled - { - get { return false; } - } - - /// - /// Always returns . - /// - public bool IsErrorEnabled - { - get { return false; } - - } - - /// - /// Always returns . - /// - public bool IsFatalEnabled - { - get { return false; } - } - - #endregion - - #region Trace - - /// - /// Ignores message. - /// - /// - public void Trace(object message) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// - /// - public void Trace(object message, Exception e) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// The format of the message object to log. - /// - public void TraceFormat(string format, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of message format arguments - public void TraceFormat(string format, Exception exception, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// the list of message format arguments - public void TraceFormat(IFormatProvider formatProvider, string format, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// The exception to log. - /// the list of message format arguments - public void TraceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// A callback used by the logger to obtain the message if log level is matched - public void Trace(FormatMessageCallback formatMessageCallback) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack trace. - public void Trace(FormatMessageCallback formatMessageCallback, Exception exception) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - public void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack trace. - public void Trace(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) - { - // NOP - no operation - } - - #endregion - - #region Debug - - /// - /// Ignores message. - /// - /// - public void Debug(object message) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// - /// - public void Debug(object message, Exception e) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// The format of the message object to log. - /// - public void DebugFormat(string format, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of message format arguments - public void DebugFormat(string format, Exception exception, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// the list of message format arguments - public void DebugFormat(IFormatProvider formatProvider, string format, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// The exception to log. - /// the list of message format arguments - public void DebugFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// A callback used by the logger to obtain the message if log level is matched - public void Debug(FormatMessageCallback formatMessageCallback) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Debug. - public void Debug(FormatMessageCallback formatMessageCallback, Exception exception) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - public void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Debug. - public void Debug(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) - { - // NOP - no operation - } - - #endregion - - #region Info - - /// - /// Ignores message. - /// - /// - public void Info(object message) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// - /// - public void Info(object message, Exception e) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// The format of the message object to log. - /// - public void InfoFormat(string format, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of message format arguments - public void InfoFormat(string format, Exception exception, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// the list of message format arguments - public void InfoFormat(IFormatProvider formatProvider, string format, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// The format of the message object to log. - /// The exception to log. - /// the list of message format arguments - public void InfoFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// A callback used by the logger to obtain the message if log level is matched - public void Info(FormatMessageCallback formatMessageCallback) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Info. - public void Info(FormatMessageCallback formatMessageCallback, Exception exception) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - public void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Info. - public void Info(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) - { - // NOP - no operation - } - - #endregion - - #region Warn - - /// - /// Ignores message. - /// - /// - public void Warn(object message) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// - /// - public void Warn(object message, Exception e) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// The format of the message object to log. - /// - public void WarnFormat(string format, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of message format arguments - public void WarnFormat(string format, Exception exception, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting Warnrmation. - /// The format of the message object to log. - /// the list of message format arguments - public void WarnFormat(IFormatProvider formatProvider, string format, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting Warnrmation. - /// The format of the message object to log. - /// The exception to log. - /// the list of message format arguments - public void WarnFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// A callback used by the logger to obtain the message if log level is matched - public void Warn(FormatMessageCallback formatMessageCallback) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Warn. - public void Warn(FormatMessageCallback formatMessageCallback, Exception exception) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - public void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Warn. - public void Warn(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) - { - // NOP - no operation - } - - #endregion - - #region Error - - /// - /// Ignores message. - /// - /// - public void Error(object message) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// - /// - public void Error(object message, Exception e) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// The format of the message object to log. - /// - public void ErrorFormat(string format, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of message format arguments - public void ErrorFormat(string format, Exception exception, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting Errorrmation. - /// The format of the message object to log. - /// the list of message format arguments - public void ErrorFormat(IFormatProvider formatProvider, string format, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting Errorrmation. - /// The format of the message object to log. - /// The exception to log. - /// the list of message format arguments - public void ErrorFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// A callback used by the logger to obtain the message if log level is matched - public void Error(FormatMessageCallback formatMessageCallback) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Error. - public void Error(FormatMessageCallback formatMessageCallback, Exception exception) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - public void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Error. - public void Error(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) - { - // NOP - no operation - } - - #endregion - - #region Fatal - - /// - /// Ignores message. - /// - /// - public void Fatal(object message) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// - /// - public void Fatal(object message, Exception e) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// The format of the message object to log. - /// - public void FatalFormat(string format, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// The format of the message object to log. - /// The exception to log. - /// the list of message format arguments - public void FatalFormat(string format, Exception exception, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting Fatalrmation. - /// The format of the message object to log. - /// the list of message format arguments - public void FatalFormat(IFormatProvider formatProvider, string format, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting Fatalrmation. - /// The format of the message object to log. - /// The exception to log. - /// the list of message format arguments - public void FatalFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// A callback used by the logger to obtain the message if log level is matched - public void Fatal(FormatMessageCallback formatMessageCallback) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Fatal. - public void Fatal(FormatMessageCallback formatMessageCallback, Exception exception) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - public void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback) - { - // NOP - no operation - } - - /// - /// Ignores message. - /// - /// An that supplies culture-specific formatting information. - /// A callback used by the logger to obtain the message if log level is matched - /// The exception to log, including its stack Fatal. - public void Fatal(IFormatProvider formatProvider, FormatMessageCallback formatMessageCallback, Exception exception) - { - // NOP - no operation - } - - #endregion - - } -} \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLoggerFactoryAdapter.cs b/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLoggerFactoryAdapter.cs deleted file mode 100644 index d1aa14b..0000000 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Simple/NoOpLoggerFactoryAdapter.cs +++ /dev/null @@ -1,102 +0,0 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 Common.Logging.Simple -{ - /// - /// Factory for creating instances that silently ignores - /// logging requests. - /// - /// - /// This logger adapter is the default used by Common.Logging if unconfigured. Using this logger adapter is the most efficient - /// way to suppress any logging output. - /// - /// Below is an example how to configure this adapter: - /// - /// <configuration> - /// - /// <configSections> - /// <sectionGroup name="common"> - /// <section name="logging" - /// type="Common.Logging.ConfigurationSectionHandler, Common.Logging" - /// requirePermission="false" /> - /// </sectionGroup> - /// </configSections> - /// - /// <common> - /// <logging> - /// <factoryAdapter type="Common.Logging.Simple.NoOpLoggerFactoryAdapter, Common.Logging"> - /// <arg key="level" value="ALL" /> - /// </factoryAdapter> - /// </logging> - /// </common> - /// - /// </configuration> - /// - /// - /// - /// - /// - /// Gilles Bayon - public sealed class NoOpLoggerFactoryAdapter : ILoggerFactoryAdapter - { - private static readonly ILog s_nopLogger = new NoOpLogger(); - - /// - /// Constructor - /// - public NoOpLoggerFactoryAdapter() - { } - - /// - /// Constructor - /// - public NoOpLoggerFactoryAdapter(NameValueCollection properties) - { } - - #region ILoggerFactoryAdapter Members - - /// - /// Get a ILog instance by type - /// - /// - /// - public ILog GetLogger(Type type) - { - return s_nopLogger; - } - - /// - /// Get a ILog instance by type name - /// - /// - /// - ILog ILoggerFactoryAdapter.GetLogger(string name) - { - return s_nopLogger; - - } - - #endregion - } -} diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Common.Logging.TestUtlis.MonoTouch.csproj b/src/Common.Logging.MonoTouch/Common.Logging.TestUtils.MonoTouch/Common.Logging.TestUtils.MonoTouch.csproj similarity index 93% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Common.Logging.TestUtlis.MonoTouch.csproj rename to src/Common.Logging.MonoTouch/Common.Logging.TestUtils.MonoTouch/Common.Logging.TestUtils.MonoTouch.csproj index 4bbee5d..f9b9867 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Common.Logging.TestUtlis.MonoTouch.csproj +++ b/src/Common.Logging.MonoTouch/Common.Logging.TestUtils.MonoTouch/Common.Logging.TestUtils.MonoTouch.csproj @@ -47,8 +47,8 @@ - - {DD9F81C2-BA9A-4212-9249-2300C62AFF6F} + + {C5FED159-541C-4245-95CA-661C4E29A2DD} Common.Logging.MonoTouch diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Logging/ILogTestsBase.cs b/src/Common.Logging.MonoTouch/Common.Logging.TestUtils.MonoTouch/Logging/ILogTestsBase.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Logging/ILogTestsBase.cs rename to src/Common.Logging.MonoTouch/Common.Logging.TestUtils.MonoTouch/Logging/ILogTestsBase.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Properties/AssemblyInfo.cs b/src/Common.Logging.MonoTouch/Common.Logging.TestUtils.MonoTouch/Properties/AssemblyInfo.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/Properties/AssemblyInfo.cs rename to src/Common.Logging.MonoTouch/Common.Logging.TestUtils.MonoTouch/Properties/AssemblyInfo.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/SerializationTestUtils.cs b/src/Common.Logging.MonoTouch/Common.Logging.TestUtils.MonoTouch/TestUtil/SerializationTestUtils.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/SerializationTestUtils.cs rename to src/Common.Logging.MonoTouch/Common.Logging.TestUtils.MonoTouch/TestUtil/SerializationTestUtils.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/TraceEventArgs.cs b/src/Common.Logging.MonoTouch/Common.Logging.TestUtils.MonoTouch/TestUtil/TraceEventArgs.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.TestUtlis.MonoTouch/TestUtil/TraceEventArgs.cs rename to src/Common.Logging.MonoTouch/Common.Logging.TestUtils.MonoTouch/TestUtil/TraceEventArgs.cs diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs b/src/Common.Logging.MonoTouch/Logging/Configuration/DefaultConfigurationReader.cs similarity index 93% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs rename to src/Common.Logging.MonoTouch/Logging/Configuration/DefaultConfigurationReader.cs index 46529d9..02a6881 100644 --- a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/Configuration/MonoTouchConfigurationReader.cs +++ b/src/Common.Logging.MonoTouch/Logging/Configuration/DefaultConfigurationReader.cs @@ -1,57 +1,57 @@ -#region License - -/* - * Copyright © 2002-2009 the original author or authors. - * - * 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 MonoTouch.Foundation; -using Common.Logging.Simple; -using System.Collections.Specialized; - -namespace Common.Logging.Configuration -{ - /// - /// MonoTouch implementation of configuration reader. Each section corresponds to a plist on the device. - /// - /// adamnation - public class MonoTouchConfigurationReader : IConfigurationReader - { - /// - /// Parses the configuration section and returns the resulting object. - /// - /// Path to the plist on the device - /// - /// NSDictionary of the settings in the plist. - /// - /// - ///

- /// Primary purpose of this method is to allow us to load settings from a plist on the device. - ///

- ///
- /// - public object GetSection (string sectionName) - { - NameValueCollection properties = new NameValueCollection(); - var nsDict = new NSDictionary (NSBundle.MainBundle.PathForResource (sectionName, null)); - foreach (var key in nsDict.Keys) - { - properties.Add(key.ToString(), nsDict[key].ToString()); - } - - return new ConsoleOutLoggerFactoryAdapter(properties); - } - } +#region License + +/* + * Copyright © 2002-2009 the original author or authors. + * + * 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 MonoTouch.Foundation; +using Common.Logging.Simple; +using System.Collections.Specialized; + +namespace Common.Logging.Configuration +{ + /// + /// MonoTouch implementation of configuration reader. Each section corresponds to a plist on the device. + /// + /// adamnation + public class DefaultConfigurationReader : IConfigurationReader + { + /// + /// Parses the configuration section and returns the resulting object. + /// + /// Path to the plist on the device + /// + /// NSDictionary of the settings in the plist. + /// + /// + ///

+ /// Primary purpose of this method is to allow us to load settings from a plist on the device. + ///

+ ///
+ /// + public object GetSection (string sectionName) + { + NameValueCollection properties = new NameValueCollection(); + var nsDict = new NSDictionary (NSBundle.MainBundle.PathForResource (sectionName, null)); + foreach (var key in nsDict.Keys) + { + properties.Add(key.ToString(), nsDict[key].ToString()); + } + + return new ConsoleOutLoggerFactoryAdapter(properties); + } + } } \ No newline at end of file diff --git a/src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/MonoNet/CollectionsUtil.cs b/src/Common.Logging.MonoTouch/Logging/MonoNet/CollectionsUtil.cs similarity index 100% rename from src/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Common.Logging.MonoTouch/Logging/MonoNet/CollectionsUtil.cs rename to src/Common.Logging.MonoTouch/Logging/MonoNet/CollectionsUtil.cs diff --git a/src/Common.Logging/Logging/LogManager.cs b/src/Common.Logging/Logging/LogManager.cs index 2f3b306..317cc29 100644 --- a/src/Common.Logging/Logging/LogManager.cs +++ b/src/Common.Logging/Logging/LogManager.cs @@ -83,8 +83,11 @@ public static class LogManager /// You can always change the source of your configuration settings by setting another instance /// on . /// +#if MONOTOUCH + public static readonly string COMMON_LOGGING_SECTION = "Settings.bundle/Common.Logging.plist"; +#else public static readonly string COMMON_LOGGING_SECTION = "common/logging"; - +#endif private static IConfigurationReader _configurationReader; private static ILoggerFactoryAdapter _adapter; private static readonly object _loadLock = new object();