diff options
author | David Christiansen <DavidChristiansen@users.noreply.github.com> | 2015-01-05 09:33:24 +0000 |
---|---|---|
committer | David Christiansen <DavidChristiansen@users.noreply.github.com> | 2015-01-05 09:33:24 +0000 |
commit | 3770a51d19a04be18ade75f59e0ff1687010a130 (patch) | |
tree | 240382c976672ed421d529860117e37677328f02 /src/DotNetOpenAuth.Core | |
parent | 7574924b2b5c810b7c00328f04f506f28da3f2ec (diff) | |
parent | a14dcb800b25d1b0477ab123b6865d90865f96f0 (diff) | |
download | DotNetOpenAuth-3770a51d19a04be18ade75f59e0ff1687010a130.zip DotNetOpenAuth-3770a51d19a04be18ade75f59e0ff1687010a130.tar.gz DotNetOpenAuth-3770a51d19a04be18ade75f59e0ff1687010a130.tar.bz2 |
Merge pull request #359 from DavidChristiansen/develop
Closes #356, Closes #357, Closes #358
Diffstat (limited to 'src/DotNetOpenAuth.Core')
17 files changed, 1502 insertions, 1838 deletions
diff --git a/src/DotNetOpenAuth.Core/App_Packages/LibLog.2.0/LibLog.cs b/src/DotNetOpenAuth.Core/App_Packages/LibLog.2.0/LibLog.cs new file mode 100644 index 0000000..5c5d1d2 --- /dev/null +++ b/src/DotNetOpenAuth.Core/App_Packages/LibLog.2.0/LibLog.cs @@ -0,0 +1,1467 @@ +//=============================================================================== +// LibLog +// +// https://github.com/damianh/LibLog +//=============================================================================== +// Copyright © 2011-2014 Damian Hickey. All rights reserved. +// +// 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. +//=============================================================================== + +#pragma warning disable 1591 + +namespace DotNetOpenAuth.Logging +{ + using System.Collections.Generic; + using DotNetOpenAuth.Logging.LogProviders; + using System; + using System.Diagnostics; + using System.Globalization; + + /// <summary> + /// Simple interface that represent a logger. + /// </summary> + public interface ILog + { + /// <summary> + /// Log a message the specified log level. + /// </summary> + /// <param name="logLevel">The log level.</param> + /// <param name="messageFunc">The message function.</param> + /// <param name="exception">An optional exception.</param> + /// <returns>true if the message was logged. Otherwise false.</returns> + /// <remarks> + /// Note to implementers: the message func should not be called if the loglevel is not enabled + /// so as not to incur performance penalties. + /// + /// To check IsEnabled call Log with only LogLevel and check the return value, no event will be written + /// </remarks> + bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception = null); + } + + /// <summary> + /// The log level. + /// </summary> + public enum LogLevel + { + Trace, + Debug, + Info, + Warn, + Error, + Fatal + } + + public static class LogExtensions + { + public static bool IsDebugEnabled(this ILog logger) + { + GuardAgainstNullLogger(logger); + return logger.Log(LogLevel.Debug, null); + } + + public static bool IsErrorEnabled(this ILog logger) + { + GuardAgainstNullLogger(logger); + return logger.Log(LogLevel.Error, null); + } + + public static bool IsFatalEnabled(this ILog logger) + { + GuardAgainstNullLogger(logger); + return logger.Log(LogLevel.Fatal, null); + } + + public static bool IsInfoEnabled(this ILog logger) + { + GuardAgainstNullLogger(logger); + return logger.Log(LogLevel.Info, null); + } + + public static bool IsTraceEnabled(this ILog logger) + { + GuardAgainstNullLogger(logger); + return logger.Log(LogLevel.Trace, null); + } + + public static bool IsWarnEnabled(this ILog logger) + { + GuardAgainstNullLogger(logger); + return logger.Log(LogLevel.Warn, null); + } + + public static void Debug(this ILog logger, Func<string> messageFunc) + { + GuardAgainstNullLogger(logger); + logger.Log(LogLevel.Debug, messageFunc); + } + + public static void Debug(this ILog logger, string message) + { + if (logger.IsDebugEnabled()) + { + logger.Log(LogLevel.Debug, message.AsFunc()); + } + } + + public static void DebugFormat(this ILog logger, string message, params object[] args) + { + if (logger.IsDebugEnabled()) + { + logger.LogFormat(LogLevel.Debug, message, args); + } + } + + public static void DebugException(this ILog logger, string message, Exception exception) + { + if (logger.IsDebugEnabled()) + { + logger.Log(LogLevel.Debug, message.AsFunc(), exception); + } + } + + public static void Error(this ILog logger, Func<string> messageFunc) + { + logger.Log(LogLevel.Error, messageFunc); + } + + public static void Error(this ILog logger, string message) + { + if (logger.IsErrorEnabled()) + { + logger.Log(LogLevel.Error, message.AsFunc()); + } + } + + public static void ErrorFormat(this ILog logger, string message, params object[] args) + { + if (logger.IsErrorEnabled()) + { + logger.LogFormat(LogLevel.Error, message, args); + } + } + + public static void ErrorException(this ILog logger, string message, Exception exception) + { + if (logger.IsErrorEnabled()) + { + logger.Log(LogLevel.Error, message.AsFunc(), exception); + } + } + + public static void Fatal(this ILog logger, Func<string> messageFunc) + { + logger.Log(LogLevel.Fatal, messageFunc); + } + + public static void Fatal(this ILog logger, string message) + { + if (logger.IsFatalEnabled()) + { + logger.Log(LogLevel.Fatal, message.AsFunc()); + } + } + + public static void FatalFormat(this ILog logger, string message, params object[] args) + { + if (logger.IsFatalEnabled()) + { + logger.LogFormat(LogLevel.Fatal, message, args); + } + } + + public static void FatalException(this ILog logger, string message, Exception exception) + { + if (logger.IsFatalEnabled()) + { + logger.Log(LogLevel.Fatal, message.AsFunc(), exception); + } + } + + public static void Info(this ILog logger, Func<string> messageFunc) + { + GuardAgainstNullLogger(logger); + logger.Log(LogLevel.Info, messageFunc); + } + + public static void Info(this ILog logger, string message) + { + if (logger.IsInfoEnabled()) + { + logger.Log(LogLevel.Info, message.AsFunc()); + } + } + + public static void InfoFormat(this ILog logger, string message, params object[] args) + { + if (logger.IsInfoEnabled()) + { + logger.LogFormat(LogLevel.Info, message, args); + } + } + + public static void InfoException(this ILog logger, string message, Exception exception) + { + if (logger.IsInfoEnabled()) + { + logger.Log(LogLevel.Info, message.AsFunc(), exception); + } + } + + public static void Trace(this ILog logger, Func<string> messageFunc) + { + GuardAgainstNullLogger(logger); + logger.Log(LogLevel.Trace, messageFunc); + } + + public static void Trace(this ILog logger, string message) + { + if (logger.IsTraceEnabled()) + { + logger.Log(LogLevel.Trace, message.AsFunc()); + } + } + + public static void TraceFormat(this ILog logger, string message, params object[] args) + { + if (logger.IsTraceEnabled()) + { + logger.LogFormat(LogLevel.Trace, message, args); + } + } + + public static void TraceException(this ILog logger, string message, Exception exception) + { + if (logger.IsTraceEnabled()) + { + logger.Log(LogLevel.Trace, message.AsFunc(), exception); + } + } + + public static void Warn(this ILog logger, Func<string> messageFunc) + { + GuardAgainstNullLogger(logger); + logger.Log(LogLevel.Warn, messageFunc); + } + + public static void Warn(this ILog logger, string message) + { + if (logger.IsWarnEnabled()) + { + logger.Log(LogLevel.Warn, message.AsFunc()); + } + } + + public static void WarnFormat(this ILog logger, string message, params object[] args) + { + if (logger.IsWarnEnabled()) + { + logger.LogFormat(LogLevel.Warn, message, args); + } + } + + public static void WarnException(this ILog logger, string message, Exception exception) + { + if (logger.IsWarnEnabled()) + { + logger.Log(LogLevel.Warn, message.AsFunc(), exception); + } + } + + private static void GuardAgainstNullLogger(ILog logger) + { + if (logger == null) + { + throw new ArgumentNullException("logger"); + } + } + + private static void LogFormat(this ILog logger, LogLevel logLevel, string message, params object[] args) + { + var result = string.Format(CultureInfo.InvariantCulture, message, args); + logger.Log(logLevel, result.AsFunc()); + } + + // Avoid the closure allocation, see https://gist.github.com/AArnott/d285feef75c18f6ecd2b + private static Func<T> AsFunc<T>(this T value) where T : class + { + return value.Return; + } + + private static T Return<T>(this T value) + { + return value; + } + } + + /// <summary> + /// Represents a way to get a <see cref="ILog"/> + /// </summary> + public interface ILogProvider + { + ILog GetLogger(string name); + } + + + /// <summary> + /// Provides a mechanism to create instances of <see cref="ILog" /> objects. + /// </summary> + public static class LogProvider + { + private static ILogProvider _currentLogProvider; + + /// <summary> + /// Gets a logger for the specified type. + /// </summary> + /// <typeparam name="T">The type whose name will be used for the logger.</typeparam> + /// <returns>An instance of <see cref="ILog"/></returns> + public static ILog For<T>() + { + return GetLogger(typeof(T)); + } + + /// <summary> + /// Gets a logger for the current class. + /// </summary> + /// <returns>An instance of <see cref="ILog"/></returns> + public static ILog GetCurrentClassLogger() + { + var stackFrame = new StackFrame(1, false); + return GetLogger(stackFrame.GetMethod().DeclaringType); + } + + /// <summary> + /// Gets a logger for the specified type. + /// </summary> + /// <param name="type">The type whose name will be used for the logger.</param> + /// <returns>An instance of <see cref="ILog"/></returns> + public static ILog GetLogger(Type type) + { + return GetLogger(type.FullName); + } + + /// <summary> + /// Gets a logger with the specified name. + /// </summary> + /// <param name="name">The name.</param> + /// <returns>An instance of <see cref="ILog"/></returns> + public static ILog GetLogger(string name) + { + ILogProvider logProvider = _currentLogProvider ?? ResolveLogProvider(); + return logProvider == null ? new NoOpLogger() : (ILog)new LoggerExecutionWrapper(logProvider.GetLogger(name)); + } + + /// <summary> + /// Sets the current log provider. + /// </summary> + /// <param name="logProvider">The log provider.</param> + public static void SetCurrentLogProvider(ILogProvider logProvider) + { + _currentLogProvider = logProvider; + } + + public delegate bool IsLoggerAvailable(); + + public delegate ILogProvider CreateLogProvider(); + + public static readonly List<Tuple<IsLoggerAvailable, CreateLogProvider>> LogProviderResolvers = + new List<Tuple<IsLoggerAvailable, CreateLogProvider>> + { + new Tuple<IsLoggerAvailable, CreateLogProvider>(SerilogLogProvider.IsLoggerAvailable, () => new SerilogLogProvider()), + new Tuple<IsLoggerAvailable, CreateLogProvider>(NLogLogProvider.IsLoggerAvailable, () => new NLogLogProvider()), + new Tuple<IsLoggerAvailable, CreateLogProvider>(Log4NetLogProvider.IsLoggerAvailable, () => new Log4NetLogProvider()), + new Tuple<IsLoggerAvailable, CreateLogProvider>(EntLibLogProvider.IsLoggerAvailable, () => new EntLibLogProvider()), + new Tuple<IsLoggerAvailable, CreateLogProvider>(LoupeLogProvider.IsLoggerAvailable, () => new LoupeLogProvider()) + }; + + private static ILogProvider ResolveLogProvider() + { + try + { + foreach(var providerResolver in LogProviderResolvers) + { + if(providerResolver.Item1()) + { + return providerResolver.Item2(); + } + } + } + catch (Exception ex) + { + Console.WriteLine( + "Exception occured resolving a log provider. Logging for this assembly {0} is disabled. {1}", + typeof(LogProvider).Assembly.FullName, + ex); + } + return null; + } + + public class NoOpLogger : ILog + { + public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception) + { + return false; + } + } + } + + public class LoggerExecutionWrapper : ILog + { + private readonly ILog _logger; + public const string FailedToGenerateLogMessage = "Failed to generate log message"; + + public ILog WrappedLogger + { + get { return _logger; } + } + + public LoggerExecutionWrapper(ILog logger) + { + _logger = logger; + } + + public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception = null) + { + if (messageFunc == null) + { + return _logger.Log(logLevel, null); + } + + Func<string> wrappedMessageFunc = () => + { + try + { + return messageFunc(); + } + catch (Exception ex) + { + Log(LogLevel.Error, () => FailedToGenerateLogMessage, ex); + } + return null; + }; + return _logger.Log(logLevel, wrappedMessageFunc, exception); + } + } +} + +namespace DotNetOpenAuth.Logging.LogProviders +{ + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.Globalization; + using System.Linq.Expressions; + using System.Reflection; + using System.Text; + using System.Threading; + + public class NLogLogProvider : ILogProvider + { + private readonly Func<string, object> _getLoggerByNameDelegate; + private static bool _providerIsAvailableOverride = true; + + public NLogLogProvider() + { + if (!IsLoggerAvailable()) + { + throw new InvalidOperationException("NLog.LogManager not found"); + } + _getLoggerByNameDelegate = GetGetLoggerMethodCall(); + } + + public static bool ProviderIsAvailableOverride + { + get { return _providerIsAvailableOverride; } + set { _providerIsAvailableOverride = value; } + } + + public ILog GetLogger(string name) + { + return new NLogLogger(_getLoggerByNameDelegate(name)); + } + + public static bool IsLoggerAvailable() + { + return ProviderIsAvailableOverride && GetLogManagerType() != null; + } + + private static Type GetLogManagerType() + { + return Type.GetType("NLog.LogManager, NLog"); + } + + private static Func<string, object> GetGetLoggerMethodCall() + { + Type logManagerType = GetLogManagerType(); + MethodInfo method = logManagerType.GetMethod("GetLogger", new[] { typeof(string) }); + ParameterExpression nameParam = Expression.Parameter(typeof(string), "name"); + MethodCallExpression methodCall = Expression.Call(null, method, new Expression[] { nameParam }); + return Expression.Lambda<Func<string, object>>(methodCall, new[] { nameParam }).Compile(); + } + + public class NLogLogger : ILog + { + private readonly dynamic _logger; + + internal NLogLogger(dynamic logger) + { + _logger = logger; + } + + public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception) + { + if (messageFunc == null) + { + return IsLogLevelEnable(logLevel); + } + if(exception != null) + { + return LogException(logLevel, messageFunc, exception); + } + switch (logLevel) + { + case LogLevel.Debug: + if (_logger.IsDebugEnabled) + { + _logger.Debug(messageFunc()); + return true; + } + break; + case LogLevel.Info: + if (_logger.IsInfoEnabled) + { + _logger.Info(messageFunc()); + return true; + } + break; + case LogLevel.Warn: + if (_logger.IsWarnEnabled) + { + _logger.Warn(messageFunc()); + return true; + } + break; + case LogLevel.Error: + if (_logger.IsErrorEnabled) + { + _logger.Error(messageFunc()); + return true; + } + break; + case LogLevel.Fatal: + if (_logger.IsFatalEnabled) + { + _logger.Fatal(messageFunc()); + return true; + } + break; + default: + if (_logger.IsTraceEnabled) + { + _logger.Trace(messageFunc()); + return true; + } + break; + } + return false; + } + + private bool LogException(LogLevel logLevel, Func<string> messageFunc, Exception exception) + { + switch (logLevel) + { + case LogLevel.Debug: + if (_logger.IsDebugEnabled) + { + _logger.DebugException(messageFunc(), exception); + return true; + } + break; + case LogLevel.Info: + if (_logger.IsInfoEnabled) + { + _logger.InfoException(messageFunc(), exception); + return true; + } + break; + case LogLevel.Warn: + if (_logger.IsWarnEnabled) + { + _logger.WarnException(messageFunc(), exception); + return true; + } + break; + case LogLevel.Error: + if (_logger.IsErrorEnabled) + { + _logger.ErrorException(messageFunc(), exception); + return true; + } + break; + case LogLevel.Fatal: + if (_logger.IsFatalEnabled) + { + _logger.FatalException(messageFunc(), exception); + return true; + } + break; + default: + if (_logger.IsTraceEnabled) + { + _logger.TraceException(messageFunc(), exception); + return true; + } + break; + } + return false; + } + + private bool IsLogLevelEnable(LogLevel logLevel) + { + switch (logLevel) + { + case LogLevel.Debug: + return _logger.IsDebugEnabled; + case LogLevel.Info: + return _logger.IsInfoEnabled; + case LogLevel.Warn: + return _logger.IsWarnEnabled; + case LogLevel.Error: + return _logger.IsErrorEnabled; + case LogLevel.Fatal: + return _logger.IsFatalEnabled; + default: + return _logger.IsTraceEnabled; + } + } + } + } + + public class Log4NetLogProvider : ILogProvider + { + private readonly Func<string, object> _getLoggerByNameDelegate; + private static bool _providerIsAvailableOverride = true; + + public Log4NetLogProvider() + { + if (!IsLoggerAvailable()) + { + throw new InvalidOperationException("log4net.LogManager not found"); + } + _getLoggerByNameDelegate = GetGetLoggerMethodCall(); + } + + public static bool ProviderIsAvailableOverride + { + get { return _providerIsAvailableOverride; } + set { _providerIsAvailableOverride = value; } + } + + public ILog GetLogger(string name) + { + return new Log4NetLogger(_getLoggerByNameDelegate(name)); + } + + public static bool IsLoggerAvailable() + { + return ProviderIsAvailableOverride && GetLogManagerType() != null; + } + + private static Type GetLogManagerType() + { + return Type.GetType("log4net.LogManager, log4net"); + } + + private static Func<string, object> GetGetLoggerMethodCall() + { + Type logManagerType = GetLogManagerType(); + MethodInfo method = logManagerType.GetMethod("GetLogger", new[] { typeof(string) }); + ParameterExpression nameParam = Expression.Parameter(typeof(string), "name"); + MethodCallExpression methodCall = Expression.Call(null, method, new Expression[] { nameParam }); + return Expression.Lambda<Func<string, object>>(methodCall, new[] { nameParam }).Compile(); + } + + public class Log4NetLogger : ILog + { + private readonly dynamic _logger; + + internal Log4NetLogger(dynamic logger) + { + _logger = logger; + } + + public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception) + { + if (messageFunc == null) + { + return IsLogLevelEnable(logLevel); + } + if (exception != null) + { + return LogException(logLevel, messageFunc, exception); + } + switch (logLevel) + { + case LogLevel.Info: + if (_logger.IsInfoEnabled) + { + _logger.Info(messageFunc()); + return true; + } + break; + case LogLevel.Warn: + if (_logger.IsWarnEnabled) + { + _logger.Warn(messageFunc()); + return true; + } + break; + case LogLevel.Error: + if (_logger.IsErrorEnabled) + { + _logger.Error(messageFunc()); + return true; + } + break; + case LogLevel.Fatal: + if (_logger.IsFatalEnabled) + { + _logger.Fatal(messageFunc()); + return true; + } + break; + default: + if (_logger.IsDebugEnabled) + { + _logger.Debug(messageFunc()); // Log4Net doesn't have a 'Trace' level, so all Trace messages are written as 'Debug' + return true; + } + break; + } + return false; + } + + private bool LogException(LogLevel logLevel, Func<string> messageFunc, Exception exception) + { + switch (logLevel) + { + case LogLevel.Info: + if (_logger.IsDebugEnabled) + { + _logger.Info(messageFunc(), exception); + return true; + } + break; + case LogLevel.Warn: + if (_logger.IsWarnEnabled) + { + _logger.Warn(messageFunc(), exception); + return true; + } + break; + case LogLevel.Error: + if (_logger.IsErrorEnabled) + { + _logger.Error(messageFunc(), exception); + return true; + } + break; + case LogLevel.Fatal: + if (_logger.IsFatalEnabled) + { + _logger.Fatal(messageFunc(), exception); + return true; + } + break; + default: + if (_logger.IsDebugEnabled) + { + _logger.Debug(messageFunc(), exception); + return true; + } + break; + } + return false; + } + + private bool IsLogLevelEnable(LogLevel logLevel) + { + switch (logLevel) + { + case LogLevel.Debug: + return _logger.IsDebugEnabled; + case LogLevel.Info: + return _logger.IsInfoEnabled; + case LogLevel.Warn: + return _logger.IsWarnEnabled; + case LogLevel.Error: + return _logger.IsErrorEnabled; + case LogLevel.Fatal: + return _logger.IsFatalEnabled; + default: + return _logger.IsDebugEnabled; + } + } + } + } + + public class EntLibLogProvider : ILogProvider + { + private const string TypeTemplate = "Microsoft.Practices.EnterpriseLibrary.Logging.{0}, Microsoft.Practices.EnterpriseLibrary.Logging"; + private static bool _providerIsAvailableOverride = true; + private static readonly Type LogEntryType; + private static readonly Type LoggerType; + private static readonly Action<string, string, TraceEventType> WriteLogEntry; + private static Func<string, TraceEventType, bool> ShouldLogEntry; + + static EntLibLogProvider() + { + LogEntryType = Type.GetType(string.Format(TypeTemplate, "LogEntry")); + LoggerType = Type.GetType(string.Format(TypeTemplate, "Logger")); + if (LogEntryType == null || LoggerType == null) + { + return; + } + WriteLogEntry = GetWriteLogEntry(); + ShouldLogEntry = GetShouldLogEntry(); + } + + public EntLibLogProvider() + { + if (!IsLoggerAvailable()) + { + throw new InvalidOperationException("Microsoft.Practices.EnterpriseLibrary.Logging.Logger not found"); + } + } + + public static bool ProviderIsAvailableOverride + { + get { return _providerIsAvailableOverride; } + set { _providerIsAvailableOverride = value; } + } + + public ILog GetLogger(string name) + { + return new EntLibLogger(name, WriteLogEntry, ShouldLogEntry); + } + + public static bool IsLoggerAvailable() + { + return ProviderIsAvailableOverride && LogEntryType != null; + } + + private static Action<string, string, TraceEventType> GetWriteLogEntry() + { + // new LogEntry(...) + var logNameParameter = Expression.Parameter(typeof(string), "logName"); + var messageParameter = Expression.Parameter(typeof(string), "message"); + var severityParameter = Expression.Parameter(typeof(TraceEventType), "severity"); + + MemberInitExpression memberInit = GetWriteLogExpression(messageParameter, severityParameter, logNameParameter); + + //Logger.Write(new LogEntry(....)); + MethodInfo writeLogEntryMethod = LoggerType.GetMethod("Write", new[] { LogEntryType }); + var writeLogEntryExpression = Expression.Call(writeLogEntryMethod, memberInit); + + return Expression.Lambda<Action<string, string, TraceEventType>>( + writeLogEntryExpression, + logNameParameter, + messageParameter, + severityParameter).Compile(); + } + + private static Func<string, TraceEventType, bool> GetShouldLogEntry() + { + // new LogEntry(...) + var logNameParameter = Expression.Parameter(typeof(string), "logName"); + var severityParameter = Expression.Parameter(typeof(TraceEventType), "severity"); + + MemberInitExpression memberInit = GetWriteLogExpression(Expression.Constant("***dummy***"), severityParameter, logNameParameter); + + //Logger.Write(new LogEntry(....)); + MethodInfo writeLogEntryMethod = LoggerType.GetMethod("ShouldLog", new[] { LogEntryType }); + var writeLogEntryExpression = Expression.Call(writeLogEntryMethod, memberInit); + + return Expression.Lambda<Func<string, TraceEventType, bool>>( + writeLogEntryExpression, + logNameParameter, + severityParameter).Compile(); + } + + private static MemberInitExpression GetWriteLogExpression(Expression message, + ParameterExpression severityParameter, ParameterExpression logNameParameter) + { + var entryType = LogEntryType; + MemberInitExpression memberInit = Expression.MemberInit(Expression.New(entryType), new MemberBinding[] + { + Expression.Bind(entryType.GetProperty("Message"), message), + Expression.Bind(entryType.GetProperty("Severity"), severityParameter), + Expression.Bind(entryType.GetProperty("TimeStamp"), + Expression.Property(null, typeof (DateTime).GetProperty("UtcNow"))), + Expression.Bind(entryType.GetProperty("Categories"), + Expression.ListInit( + Expression.New(typeof (List<string>)), + typeof (List<string>).GetMethod("Add", new[] {typeof (string)}), + logNameParameter)) + }); + return memberInit; + } + + public class EntLibLogger : ILog + { + private readonly string _loggerName; + private readonly Action<string, string, TraceEventType> _writeLog; + private readonly Func<string, TraceEventType, bool> _shouldLog; + + internal EntLibLogger(string loggerName, Action<string, string, TraceEventType> writeLog, Func<string, TraceEventType, bool> shouldLog) + { + _loggerName = loggerName; + _writeLog = writeLog; + _shouldLog = shouldLog; + } + + public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception) + { + var severity = MapSeverity(logLevel); + if (messageFunc == null) + { + return _shouldLog(_loggerName, severity); + } + if (exception != null) + { + return LogException(logLevel, messageFunc, exception); + } + _writeLog(_loggerName, messageFunc(), severity); + return true; + } + + public bool LogException(LogLevel logLevel, Func<string> messageFunc, Exception exception) + { + var severity = MapSeverity(logLevel); + var message = messageFunc() + Environment.NewLine + exception; + _writeLog(_loggerName, message, severity); + return true; + } + + private static TraceEventType MapSeverity(LogLevel logLevel) + { + switch (logLevel) + { + case LogLevel.Fatal: + return TraceEventType.Critical; + case LogLevel.Error: + return TraceEventType.Error; + case LogLevel.Warn: + return TraceEventType.Warning; + case LogLevel.Info: + return TraceEventType.Information; + default: + return TraceEventType.Verbose; + } + } + } + } + + public class SerilogLogProvider : ILogProvider + { + private readonly Func<string, object> _getLoggerByNameDelegate; + private static bool _providerIsAvailableOverride = true; + + public SerilogLogProvider() + { + if (!IsLoggerAvailable()) + { + throw new InvalidOperationException("Serilog.Log not found"); + } + _getLoggerByNameDelegate = GetForContextMethodCall(); + } + + public static bool ProviderIsAvailableOverride + { + get { return _providerIsAvailableOverride; } + set { _providerIsAvailableOverride = value; } + } + + public ILog GetLogger(string name) + { + return new SerilogLogger(_getLoggerByNameDelegate(name)); + } + + public static bool IsLoggerAvailable() + { + return ProviderIsAvailableOverride && GetLogManagerType() != null; + } + + private static Type GetLogManagerType() + { + return Type.GetType("Serilog.Log, Serilog"); + } + + private static Func<string, object> GetForContextMethodCall() + { + Type logManagerType = GetLogManagerType(); + MethodInfo method = logManagerType.GetMethod("ForContext", new[] { typeof(string), typeof(object), typeof(bool) }); + ParameterExpression propertyNameParam = Expression.Parameter(typeof(string), "propertyName"); + ParameterExpression valueParam = Expression.Parameter(typeof(object), "value"); + ParameterExpression destructureObjectsParam = Expression.Parameter(typeof(bool), "destructureObjects"); + MethodCallExpression methodCall = Expression.Call(null, method, new Expression[] + { + propertyNameParam, + valueParam, + destructureObjectsParam + }); + var func = Expression.Lambda<Func<string, object, bool, object>>(methodCall, new[] + { + propertyNameParam, + valueParam, + destructureObjectsParam + }).Compile(); + return name => func("Name", name, false); + } + + public class SerilogLogger : ILog + { + private readonly object _logger; + private static readonly object DebugLevel; + private static readonly object ErrorLevel; + private static readonly object FatalLevel; + private static readonly object InformationLevel; + private static readonly object VerboseLevel; + private static readonly object WarningLevel; + private static readonly Func<object, object, bool> IsEnabled; + private static readonly Action<object, object, string> Write; + private static readonly Action<object, object, Exception, string> WriteException; + + static SerilogLogger() + { + var logEventTypeType = Type.GetType("Serilog.Events.LogEventLevel, Serilog"); + DebugLevel = Enum.Parse(logEventTypeType, "Debug"); + ErrorLevel = Enum.Parse(logEventTypeType, "Error"); + FatalLevel = Enum.Parse(logEventTypeType, "Fatal"); + InformationLevel = Enum.Parse(logEventTypeType, "Information"); + VerboseLevel = Enum.Parse(logEventTypeType, "Verbose"); + WarningLevel = Enum.Parse(logEventTypeType, "Warning"); + + // Func<object, object, bool> isEnabled = (logger, level) => { return ((SeriLog.ILogger)logger).IsEnabled(level); } + var loggerType = Type.GetType("Serilog.ILogger, Serilog"); + MethodInfo isEnabledMethodInfo = loggerType.GetMethod("IsEnabled"); + ParameterExpression instanceParam = Expression.Parameter(typeof(object)); + UnaryExpression instanceCast = Expression.Convert(instanceParam, loggerType); + ParameterExpression levelParam = Expression.Parameter(typeof(object)); + UnaryExpression levelCast = Expression.Convert(levelParam, logEventTypeType); + MethodCallExpression isEnabledMethodCall = Expression.Call(instanceCast, isEnabledMethodInfo, levelCast); + IsEnabled = Expression.Lambda<Func<object, object, bool>>(isEnabledMethodCall, new[] + { + instanceParam, + levelParam + }).Compile(); + + // Action<object, object, string> Write = + // (logger, level, message) => { ((SeriLog.ILoggerILogger)logger).Write(level, message, new object[]); } + MethodInfo writeMethodInfo = loggerType.GetMethod("Write", new[] { logEventTypeType, typeof(string), typeof(object[]) }); + ParameterExpression messageParam = Expression.Parameter(typeof(string)); + ConstantExpression propertyValuesParam = Expression.Constant(new object[0]); + MethodCallExpression writeMethodExp = Expression.Call(instanceCast, writeMethodInfo, levelCast, messageParam, propertyValuesParam); + Write = Expression.Lambda<Action<object, object, string>>(writeMethodExp, new[] + { + instanceParam, + levelParam, + messageParam + }).Compile(); + + // Action<object, object, string, Exception> WriteException = + // (logger, level, exception, message) => { ((ILogger)logger).Write(level, exception, message, new object[]); } + MethodInfo writeExceptionMethodInfo = loggerType.GetMethod("Write", new[] + { + logEventTypeType, + typeof(Exception), + typeof(string), + typeof(object[]) + }); + ParameterExpression exceptionParam = Expression.Parameter(typeof(Exception)); + writeMethodExp = Expression.Call( + instanceCast, + writeExceptionMethodInfo, + levelCast, + exceptionParam, + messageParam, + propertyValuesParam); + WriteException = Expression.Lambda<Action<object, object, Exception, string>>(writeMethodExp, new[] + { + instanceParam, + levelParam, + exceptionParam, + messageParam, + }).Compile(); + } + + internal SerilogLogger(object logger) + { + _logger = logger; + } + + public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception) + { + if (messageFunc == null) + { + return IsEnabled(_logger, logLevel); + } + if (exception != null) + { + return LogException(logLevel, messageFunc, exception); + } + + switch (logLevel) + { + case LogLevel.Debug: + if (IsEnabled(_logger, DebugLevel)) + { + Write(_logger, DebugLevel, messageFunc()); + return true; + } + break; + case LogLevel.Info: + if (IsEnabled(_logger, InformationLevel)) + { + Write(_logger, InformationLevel, messageFunc()); + return true; + } + break; + case LogLevel.Warn: + if (IsEnabled(_logger, WarningLevel)) + { + Write(_logger, WarningLevel, messageFunc()); + return true; + } + break; + case LogLevel.Error: + if (IsEnabled(_logger, ErrorLevel)) + { + Write(_logger, ErrorLevel, messageFunc()); + return true; + } + break; + case LogLevel.Fatal: + if (IsEnabled(_logger, FatalLevel)) + { + Write(_logger, FatalLevel, messageFunc()); + return true; + } + break; + default: + if (IsEnabled(_logger, VerboseLevel)) + { + Write(_logger, VerboseLevel, messageFunc()); + return true; + } + break; + } + return false; + } + + private bool LogException(LogLevel logLevel, Func<string> messageFunc, Exception exception) + { + switch (logLevel) + { + case LogLevel.Debug: + if (IsEnabled(_logger, DebugLevel)) + { + WriteException(_logger, DebugLevel, exception, messageFunc()); + return true; + } + break; + case LogLevel.Info: + if (IsEnabled(_logger, InformationLevel)) + { + WriteException(_logger, InformationLevel, exception, messageFunc()); + return true; + } + break; + case LogLevel.Warn: + if (IsEnabled(_logger, WarningLevel)) + { + WriteException(_logger, WarningLevel, exception, messageFunc()); + return true; + } + break; + case LogLevel.Error: + if (IsEnabled(_logger, ErrorLevel)) + { + WriteException(_logger, ErrorLevel, exception, messageFunc()); + return true; + } + break; + case LogLevel.Fatal: + if (IsEnabled(_logger, FatalLevel)) + { + WriteException(_logger, FatalLevel, exception, messageFunc()); + return true; + } + break; + default: + if (IsEnabled(_logger, VerboseLevel)) + { + WriteException(_logger, VerboseLevel, exception, messageFunc()); + return true; + } + break; + } + return false; + } + } + } + + public class LoupeLogProvider : ILogProvider + { + private static bool _providerIsAvailableOverride = true; + private readonly WriteDelegate _logWriteDelegate; + + public LoupeLogProvider() + { + if (!IsLoggerAvailable()) + { + throw new InvalidOperationException("Gibraltar.Agent.Log (Loupe) not found"); + } + + _logWriteDelegate = GetLogWriteDelegate(); + } + + /// <summary> + /// Gets or sets a value indicating whether [provider is available override]. Used in tests. + /// </summary> + /// <value> + /// <c>true</c> if [provider is available override]; otherwise, <c>false</c>. + /// </value> + public static bool ProviderIsAvailableOverride + { + get { return _providerIsAvailableOverride; } + set { _providerIsAvailableOverride = value; } + } + + public ILog GetLogger(string name) + { + return new LoupeLogger(name, _logWriteDelegate); + } + + public static bool IsLoggerAvailable() + { + return ProviderIsAvailableOverride && GetLogManagerType() != null; + } + + private static Type GetLogManagerType() + { + return Type.GetType("Gibraltar.Agent.Log, Gibraltar.Agent"); + } + + private static WriteDelegate GetLogWriteDelegate() + { + Type logManagerType = GetLogManagerType(); + Type logMessageSeverityType = Type.GetType("Gibraltar.Agent.LogMessageSeverity, Gibraltar.Agent"); + Type logWriteModeType = Type.GetType("Gibraltar.Agent.LogWriteMode, Gibraltar.Agent"); + + MethodInfo method = logManagerType.GetMethod("Write", new[] + { + logMessageSeverityType, typeof(string), typeof(int), typeof(Exception), typeof(bool), + logWriteModeType, typeof(string), typeof(string), typeof(string), typeof(string), typeof(object[]) + }); + + var callDelegate = (WriteDelegate)Delegate.CreateDelegate(typeof(WriteDelegate), method); + return callDelegate; + } + + public class LoupeLogger : ILog + { + private const string LogSystem = "LibLog"; + + private readonly string _category; + private readonly WriteDelegate _logWriteDelegate; + private readonly int _skipLevel; + + internal LoupeLogger(string category, WriteDelegate logWriteDelegate) + { + _category = category; + _logWriteDelegate = logWriteDelegate; + _skipLevel = 1; + } + + public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception) + { + if (messageFunc == null) + { + //nothing to log.. + return true; + } + + _logWriteDelegate((int)ToLogMessageSeverity(logLevel), LogSystem, _skipLevel, exception, true, 0, null, + _category, null, messageFunc.Invoke()); + + return true; + } + + public TraceEventType ToLogMessageSeverity(LogLevel logLevel) + { + switch (logLevel) + { + case LogLevel.Trace: + return TraceEventType.Verbose; + case LogLevel.Debug: + return TraceEventType.Verbose; + case LogLevel.Info: + return TraceEventType.Information; + case LogLevel.Warn: + return TraceEventType.Warning; + case LogLevel.Error: + return TraceEventType.Error; + case LogLevel.Fatal: + return TraceEventType.Critical; + default: + throw new ArgumentOutOfRangeException("logLevel"); + } + } + } + + /// <summary> + /// The form of the Loupe Log.Write method we're using + /// </summary> + internal delegate void WriteDelegate( + int severity, + string logSystem, + int skipFrames, + Exception exception, + bool attributeToException, + int writeMode, + string detailsXml, + string category, + string caption, + string description, + params object[] args + ); + } + + public class ColouredConsoleLogProvider : ILogProvider + { + static ColouredConsoleLogProvider() + { + MessageFormatter = DefaultMessageFormatter; + Colors = new Dictionary<LogLevel, ConsoleColor> { + { LogLevel.Fatal, ConsoleColor.Red }, + { LogLevel.Error, ConsoleColor.Yellow }, + { LogLevel.Warn, ConsoleColor.Magenta }, + { LogLevel.Info, ConsoleColor.White }, + { LogLevel.Debug, ConsoleColor.Gray }, + { LogLevel.Trace, ConsoleColor.DarkGray }, + }; + } + + public ILog GetLogger(string name) + { + return new ColouredConsoleLogger(name); + } + + /// <summary> + /// A delegate returning a formatted log message + /// </summary> + /// <param name="loggerName">The name of the Logger</param> + /// <param name="level">The Log Level</param> + /// <param name="message">The Log Message</param> + /// <param name="e">The Exception, if there is one</param> + /// <returns>A formatted Log Message string.</returns> + public delegate string MessageFormatterDelegate( + string loggerName, + LogLevel level, + object message, + Exception e); + + public static Dictionary<LogLevel, ConsoleColor> Colors { get; set; } + + public static MessageFormatterDelegate MessageFormatter { get; set; } + + protected static string DefaultMessageFormatter(string loggerName, LogLevel level, object message, Exception e) + { + var stringBuilder = new StringBuilder(); + + stringBuilder.Append(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture)); + + stringBuilder.Append(" "); + + // Append a readable representation of the log level + stringBuilder.Append(("[" + level.ToString().ToUpper() + "]").PadRight(8)); + + stringBuilder.Append("(" + loggerName + ") "); + + // Append the message + stringBuilder.Append(message); + + // Append stack trace if there is an exception + if (e != null) + { + stringBuilder.Append(Environment.NewLine).Append(e.GetType()); + stringBuilder.Append(Environment.NewLine).Append(e.Message); + stringBuilder.Append(Environment.NewLine).Append(e.StackTrace); + } + + return stringBuilder.ToString(); + } + + public class ColouredConsoleLogger : ILog + { + private readonly string _name; + + public ColouredConsoleLogger(string name) + { + _name = name; + } + + public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception) + { + if (messageFunc == null) + { + return true; + } + + Write(logLevel, messageFunc(), exception); + return true; + } + + protected void Write(LogLevel logLevel, string message, Exception e = null) + { + var formattedMessage = MessageFormatter(this._name, logLevel, message, e); + ConsoleColor color; + + if (Colors.TryGetValue(logLevel, out color)) + { + var originalColor = Console.ForegroundColor; + try + { + Console.ForegroundColor = color; + Console.Out.WriteLine(formattedMessage); + } + finally + { + Console.ForegroundColor = originalColor; + } + } + else + { + Console.Out.WriteLine(formattedMessage); + } + } + } + } +} diff --git a/src/DotNetOpenAuth.Core/DotNetOpenAuth.Core.csproj b/src/DotNetOpenAuth.Core/DotNetOpenAuth.Core.csproj index 0781b76..77d767b 100644 --- a/src/DotNetOpenAuth.Core/DotNetOpenAuth.Core.csproj +++ b/src/DotNetOpenAuth.Core/DotNetOpenAuth.Core.csproj @@ -19,6 +19,7 @@ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> </PropertyGroup> <ItemGroup> + <Compile Include="App_Packages\LibLog.2.0\LibLog.cs" /> <Compile Include="Assumes.cs" /> <Compile Include="IHostFactories.cs" /> <Compile Include="IRequireHostFactories.cs" /> @@ -128,11 +129,6 @@ <Compile Include="Configuration\HostNameElement.cs" /> <Compile Include="IEmbeddedResourceRetrieval.cs" /> <Compile Include="Logger.cs" /> - <Compile Include="Loggers\ILog.cs" /> - <Compile Include="Loggers\Log4NetLogger.cs" /> - <Compile Include="Loggers\NLogLogger.cs" /> - <Compile Include="Loggers\NoOpLogger.cs" /> - <Compile Include="Loggers\TraceLogger.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Messaging\ReadOnlyDictionary.cs" /> <Compile Include="Reporting.cs" /> @@ -169,14 +165,7 @@ <EmbeddedResource Include="Messaging\MessagingStrings.sr.resx" /> </ItemGroup> <ItemGroup> - <Reference Include="log4net, Version=1.2.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\log4net.2.0.2\lib\net40-full\log4net.dll</HintPath> - </Reference> - <Reference Include="NLog, Version=2.1.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\NLog.2.1.0\lib\net45\NLog.dll</HintPath> - </Reference> + <Reference Include="Microsoft.CSharp" /> <Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http.Extensions"> <HintPath>..\packages\Microsoft.Net.Http.2.2.15\lib\net45\System.Net.Http.Extensions.dll</HintPath> diff --git a/src/DotNetOpenAuth.Core/Logger.cs b/src/DotNetOpenAuth.Core/Logger.cs index a8b977e..f82b2e6 100644 --- a/src/DotNetOpenAuth.Core/Logger.cs +++ b/src/DotNetOpenAuth.Core/Logger.cs @@ -7,12 +7,12 @@ namespace DotNetOpenAuth { using System; using System.Globalization; - using DotNetOpenAuth.Loggers; + using DotNetOpenAuth.Logging; + using DotNetOpenAuth.Logging.LogProviders; using DotNetOpenAuth.Messaging; - using log4net.Core; using Validation; - /// <summary> + /// <summary> /// A general logger for the entire DotNetOpenAuth library. /// </summary> /// <remarks> @@ -167,8 +167,7 @@ namespace DotNetOpenAuth { /// <param name="name">The name of the log to initialize.</param> /// <returns>The <see cref="ILog"/> instance of the logger to use.</returns> private static ILog InitializeFacade(string name) { - ILog result = Log4NetLogger.Initialize(name) ?? NLogLogger.Initialize(name) ?? TraceLogger.Initialize(name) ?? NoOpLogger.Initialize(); - return result; + return LogProvider.GetLogger(name); } } } diff --git a/src/DotNetOpenAuth.Core/Loggers/ILog.cs b/src/DotNetOpenAuth.Core/Loggers/ILog.cs deleted file mode 100644 index e801b2a..0000000 --- a/src/DotNetOpenAuth.Core/Loggers/ILog.cs +++ /dev/null @@ -1,851 +0,0 @@ -// <auto-generated /> - -#region Copyright & License -// -// Copyright 2001-2006 The Apache Software Foundation -// -// 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 - -// This interface is designed to look like log4net's ILog interface. -// We have this as a facade in front of it to avoid crashing if the -// hosting web site chooses not to deploy log4net.dll along with -// DotNetOpenAuth.dll. - -namespace DotNetOpenAuth.Loggers -{ - using System; - using System.Reflection; - using log4net; - using log4net.Core; - - /// <summary> - /// The ILog interface is use by application to log messages into - /// the log4net framework. - /// </summary> - /// <remarks> - /// <para> - /// Use the <see cref="LogManager"/> to obtain logger instances - /// that implement this interface. The <see cref="LogManager.GetLogger(Assembly,Type)"/> - /// static method is used to get logger instances. - /// </para> - /// <para> - /// This class contains methods for logging at different levels and also - /// has properties for determining if those logging levels are - /// enabled in the current configuration. - /// </para> - /// <para> - /// This interface can be implemented in different ways. This documentation - /// specifies reasonable behavior that a caller can expect from the actual - /// implementation, however different implementations reserve the right to - /// do things differently. - /// </para> - /// </remarks> - /// <example>Simple example of logging messages - /// <code lang="C#"> - /// ILog log = LogManager.GetLogger("application-log"); - /// - /// log.Info("Application Start"); - /// log.Debug("This is a debug message"); - /// - /// if (log.IsDebugEnabled) - /// { - /// log.Debug("This is another debug message"); - /// } - /// </code> - /// </example> - /// <seealso cref="LogManager"/> - /// <seealso cref="LogManager.GetLogger(Assembly, Type)"/> - /// <author>Nicko Cadell</author> - /// <author>Gert Driesen</author> - interface ILog - { - /// <overloads>Log a message object with the <see cref="Level.Debug"/> level.</overloads> - /// <summary> - /// Log a message object with the <see cref="Level.Debug"/> level. - /// </summary> - /// <param name="message">The message object to log.</param> - /// <remarks> - /// <para> - /// This method first checks if this logger is <c>DEBUG</c> - /// enabled by comparing the level of this logger with the - /// <see cref="Level.Debug"/> level. If this logger is - /// <c>DEBUG</c> enabled, then it converts the message object - /// (passed as parameter) to a string by invoking the appropriate - /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then - /// proceeds to call all the registered appenders in this logger - /// and also higher in the hierarchy depending on the value of - /// the additivity flag. - /// </para> - /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/> - /// to this method will print the name of the <see cref="Exception"/> - /// but no stack trace. To print a stack trace use the - /// <see cref="Debug(object,Exception)"/> form instead. - /// </para> - /// </remarks> - /// <seealso cref="Debug(object,Exception)"/> - /// <seealso cref="IsDebugEnabled"/> - void Debug(object message); - - /// <summary> - /// Log a message object with the <see cref="Level.Debug"/> level including - /// the stack trace of the <see cref="Exception"/> passed - /// as a parameter. - /// </summary> - /// <param name="message">The message object to log.</param> - /// <param name="exception">The exception to log, including its stack trace.</param> - /// <remarks> - /// <para> - /// See the <see cref="Debug(object)"/> form for more detailed information. - /// </para> - /// </remarks> - /// <seealso cref="Debug(object)"/> - /// <seealso cref="IsDebugEnabled"/> - void Debug(object message, Exception exception); - - /// <overloads>Log a formatted string with the <see cref="Level.Debug"/> level.</overloads> - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Debug"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="args">An Object array containing zero or more objects to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Debug(object)"/> - /// <seealso cref="IsDebugEnabled"/> - void DebugFormat(string format, params object[] args); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Debug"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Debug(object)"/> - /// <seealso cref="IsDebugEnabled"/> - void DebugFormat(string format, object arg0); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Debug"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <param name="arg1">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Debug(object)"/> - /// <seealso cref="IsDebugEnabled"/> - void DebugFormat(string format, object arg0, object arg1); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Debug"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <param name="arg1">An Object to format</param> - /// <param name="arg2">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Debug(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Debug(object)"/> - /// <seealso cref="IsDebugEnabled"/> - void DebugFormat(string format, object arg0, object arg1, object arg2); - - /// <overloads>Log a message object with the <see cref="Level.Info"/> level.</overloads> - /// <summary> - /// Logs a message object with the <see cref="Level.Info"/> level. - /// </summary> - /// <remarks> - /// <para> - /// This method first checks if this logger is <c>INFO</c> - /// enabled by comparing the level of this logger with the - /// <see cref="Level.Info"/> level. If this logger is - /// <c>INFO</c> enabled, then it converts the message object - /// (passed as parameter) to a string by invoking the appropriate - /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then - /// proceeds to call all the registered appenders in this logger - /// and also higher in the hierarchy depending on the value of the - /// additivity flag. - /// </para> - /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/> - /// to this method will print the name of the <see cref="Exception"/> - /// but no stack trace. To print a stack trace use the - /// <see cref="Info(object,Exception)"/> form instead. - /// </para> - /// </remarks> - /// <param name="message">The message object to log.</param> - /// <seealso cref="Info(object,Exception)"/> - /// <seealso cref="IsInfoEnabled"/> - void Info(object message); - - /// <summary> - /// Logs a message object with the <c>INFO</c> level including - /// the stack trace of the <see cref="Exception"/> passed - /// as a parameter. - /// </summary> - /// <param name="message">The message object to log.</param> - /// <param name="exception">The exception to log, including its stack trace.</param> - /// <remarks> - /// <para> - /// See the <see cref="Info(object)"/> form for more detailed information. - /// </para> - /// </remarks> - /// <seealso cref="Info(object)"/> - /// <seealso cref="IsInfoEnabled"/> - void Info(object message, Exception exception); - - /// <overloads>Log a formatted message string with the <see cref="Level.Info"/> level.</overloads> - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Info"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="args">An Object array containing zero or more objects to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Info(object,Exception)"/> - /// <seealso cref="IsInfoEnabled"/> - void InfoFormat(string format, params object[] args); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Info"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Info(object)"/> - /// <seealso cref="IsInfoEnabled"/> - void InfoFormat(string format, object arg0); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Info"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <param name="arg1">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Info(object)"/> - /// <seealso cref="IsInfoEnabled"/> - void InfoFormat(string format, object arg0, object arg1); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Info"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <param name="arg1">An Object to format</param> - /// <param name="arg2">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Info(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Info(object)"/> - /// <seealso cref="IsInfoEnabled"/> - void InfoFormat(string format, object arg0, object arg1, object arg2); - - /// <overloads>Log a message object with the <see cref="Level.Warn"/> level.</overloads> - /// <summary> - /// Log a message object with the <see cref="Level.Warn"/> level. - /// </summary> - /// <remarks> - /// <para> - /// This method first checks if this logger is <c>WARN</c> - /// enabled by comparing the level of this logger with the - /// <see cref="Level.Warn"/> level. If this logger is - /// <c>WARN</c> enabled, then it converts the message object - /// (passed as parameter) to a string by invoking the appropriate - /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then - /// proceeds to call all the registered appenders in this logger - /// and also higher in the hierarchy depending on the value of the - /// additivity flag. - /// </para> - /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/> - /// to this method will print the name of the <see cref="Exception"/> - /// but no stack trace. To print a stack trace use the - /// <see cref="Warn(object,Exception)"/> form instead. - /// </para> - /// </remarks> - /// <param name="message">The message object to log.</param> - /// <seealso cref="Warn(object,Exception)"/> - /// <seealso cref="IsWarnEnabled"/> - void Warn(object message); - - /// <summary> - /// Log a message object with the <see cref="Level.Warn"/> level including - /// the stack trace of the <see cref="Exception"/> passed - /// as a parameter. - /// </summary> - /// <param name="message">The message object to log.</param> - /// <param name="exception">The exception to log, including its stack trace.</param> - /// <remarks> - /// <para> - /// See the <see cref="Warn(object)"/> form for more detailed information. - /// </para> - /// </remarks> - /// <seealso cref="Warn(object)"/> - /// <seealso cref="IsWarnEnabled"/> - void Warn(object message, Exception exception); - - /// <overloads>Log a formatted message string with the <see cref="Level.Warn"/> level.</overloads> - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Warn"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="args">An Object array containing zero or more objects to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Warn(object,Exception)"/> - /// <seealso cref="IsWarnEnabled"/> - void WarnFormat(string format, params object[] args); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Warn"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Warn(object)"/> - /// <seealso cref="IsWarnEnabled"/> - void WarnFormat(string format, object arg0); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Warn"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <param name="arg1">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Warn(object)"/> - /// <seealso cref="IsWarnEnabled"/> - void WarnFormat(string format, object arg0, object arg1); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Warn"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <param name="arg1">An Object to format</param> - /// <param name="arg2">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Warn(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Warn(object)"/> - /// <seealso cref="IsWarnEnabled"/> - void WarnFormat(string format, object arg0, object arg1, object arg2); - - /// <overloads>Log a message object with the <see cref="Level.Error"/> level.</overloads> - /// <summary> - /// Logs a message object with the <see cref="Level.Error"/> level. - /// </summary> - /// <param name="message">The message object to log.</param> - /// <remarks> - /// <para> - /// This method first checks if this logger is <c>ERROR</c> - /// enabled by comparing the level of this logger with the - /// <see cref="Level.Error"/> level. If this logger is - /// <c>ERROR</c> enabled, then it converts the message object - /// (passed as parameter) to a string by invoking the appropriate - /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then - /// proceeds to call all the registered appenders in this logger - /// and also higher in the hierarchy depending on the value of the - /// additivity flag. - /// </para> - /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/> - /// to this method will print the name of the <see cref="Exception"/> - /// but no stack trace. To print a stack trace use the - /// <see cref="Error(object,Exception)"/> form instead. - /// </para> - /// </remarks> - /// <seealso cref="Error(object,Exception)"/> - /// <seealso cref="IsErrorEnabled"/> - void Error(object message); - - /// <summary> - /// Log a message object with the <see cref="Level.Error"/> level including - /// the stack trace of the <see cref="Exception"/> passed - /// as a parameter. - /// </summary> - /// <param name="message">The message object to log.</param> - /// <param name="exception">The exception to log, including its stack trace.</param> - /// <remarks> - /// <para> - /// See the <see cref="Error(object)"/> form for more detailed information. - /// </para> - /// </remarks> - /// <seealso cref="Error(object)"/> - /// <seealso cref="IsErrorEnabled"/> - void Error(object message, Exception exception); - - /// <overloads>Log a formatted message string with the <see cref="Level.Error"/> level.</overloads> - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Error"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="args">An Object array containing zero or more objects to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Error(object,Exception)"/> - /// <seealso cref="IsErrorEnabled"/> - void ErrorFormat(string format, params object[] args); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Error"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Error(object)"/> - /// <seealso cref="IsErrorEnabled"/> - void ErrorFormat(string format, object arg0); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Error"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <param name="arg1">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Error(object)"/> - /// <seealso cref="IsErrorEnabled"/> - void ErrorFormat(string format, object arg0, object arg1); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Error"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <param name="arg1">An Object to format</param> - /// <param name="arg2">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Error(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Error(object)"/> - /// <seealso cref="IsErrorEnabled"/> - void ErrorFormat(string format, object arg0, object arg1, object arg2); - - /// <overloads>Log a message object with the <see cref="Level.Fatal"/> level.</overloads> - /// <summary> - /// Log a message object with the <see cref="Level.Fatal"/> level. - /// </summary> - /// <remarks> - /// <para> - /// This method first checks if this logger is <c>FATAL</c> - /// enabled by comparing the level of this logger with the - /// <see cref="Level.Fatal"/> level. If this logger is - /// <c>FATAL</c> enabled, then it converts the message object - /// (passed as parameter) to a string by invoking the appropriate - /// <see cref="log4net.ObjectRenderer.IObjectRenderer"/>. It then - /// proceeds to call all the registered appenders in this logger - /// and also higher in the hierarchy depending on the value of the - /// additivity flag. - /// </para> - /// <para><b>WARNING</b> Note that passing an <see cref="Exception"/> - /// to this method will print the name of the <see cref="Exception"/> - /// but no stack trace. To print a stack trace use the - /// <see cref="Fatal(object,Exception)"/> form instead. - /// </para> - /// </remarks> - /// <param name="message">The message object to log.</param> - /// <seealso cref="Fatal(object,Exception)"/> - /// <seealso cref="IsFatalEnabled"/> - void Fatal(object message); - - /// <summary> - /// Log a message object with the <see cref="Level.Fatal"/> level including - /// the stack trace of the <see cref="Exception"/> passed - /// as a parameter. - /// </summary> - /// <param name="message">The message object to log.</param> - /// <param name="exception">The exception to log, including its stack trace.</param> - /// <remarks> - /// <para> - /// See the <see cref="Fatal(object)"/> form for more detailed information. - /// </para> - /// </remarks> - /// <seealso cref="Fatal(object)"/> - /// <seealso cref="IsFatalEnabled"/> - void Fatal(object message, Exception exception); - - /// <overloads>Log a formatted message string with the <see cref="Level.Fatal"/> level.</overloads> - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Fatal"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="args">An Object array containing zero or more objects to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Fatal(object,Exception)"/> - /// <seealso cref="IsFatalEnabled"/> - void FatalFormat(string format, params object[] args); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Fatal"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Fatal(object)"/> - /// <seealso cref="IsFatalEnabled"/> - void FatalFormat(string format, object arg0); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Fatal"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <param name="arg1">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Fatal(object)"/> - /// <seealso cref="IsFatalEnabled"/> - void FatalFormat(string format, object arg0, object arg1); - - /// <summary> - /// Logs a formatted message string with the <see cref="Level.Fatal"/> level. - /// </summary> - /// <param name="format">A String containing zero or more format items</param> - /// <param name="arg0">An Object to format</param> - /// <param name="arg1">An Object to format</param> - /// <param name="arg2">An Object to format</param> - /// <remarks> - /// <para> - /// The message is formatted using the <c>string.Format</c> method. See - /// <see cref="string.Format(string, object[])"/> for details of the syntax of the format string and the behavior - /// of the formatting. - /// </para> - /// <para> - /// This method does not take an <see cref="Exception"/> object to include in the - /// log event. To pass an <see cref="Exception"/> use one of the <see cref="Fatal(object,Exception)"/> - /// methods instead. - /// </para> - /// </remarks> - /// <seealso cref="Fatal(object)"/> - /// <seealso cref="IsFatalEnabled"/> - void FatalFormat(string format, object arg0, object arg1, object arg2); - - /// <summary> - /// Checks if this logger is enabled for the <see cref="Level.Debug"/> level. - /// </summary> - /// <value> - /// <c>true</c> if this logger is enabled for <see cref="Level.Debug"/> events, <c>false</c> otherwise. - /// </value> - /// <remarks> - /// <para> - /// This function is intended to lessen the computational cost of - /// disabled log debug statements. - /// </para> - /// <para> For some ILog interface <c>log</c>, when you write:</para> - /// <code lang="C#"> - /// log.Debug("This is entry number: " + i ); - /// </code> - /// <para> - /// You incur the cost constructing the message, string construction and concatenation in - /// this case, regardless of whether the message is logged or not. - /// </para> - /// <para> - /// If you are worried about speed (who isn't), then you should write: - /// </para> - /// <code lang="C#"> - /// if (log.IsDebugEnabled) - /// { - /// log.Debug("This is entry number: " + i ); - /// } - /// </code> - /// <para> - /// This way you will not incur the cost of parameter - /// construction if debugging is disabled for <c>log</c>. On - /// the other hand, if the <c>log</c> is debug enabled, you - /// will incur the cost of evaluating whether the logger is debug - /// enabled twice. Once in <see cref="IsDebugEnabled"/> and once in - /// the <see cref="Debug(object)"/>. This is an insignificant overhead - /// since evaluating a logger takes about 1% of the time it - /// takes to actually log. This is the preferred style of logging. - /// </para> - /// <para>Alternatively if your logger is available statically then the is debug - /// enabled state can be stored in a static variable like this: - /// </para> - /// <code lang="C#"> - /// private static readonly bool isDebugEnabled = log.IsDebugEnabled; - /// </code> - /// <para> - /// Then when you come to log you can write: - /// </para> - /// <code lang="C#"> - /// if (isDebugEnabled) - /// { - /// log.Debug("This is entry number: " + i ); - /// } - /// </code> - /// <para> - /// This way the debug enabled state is only queried once - /// when the class is loaded. Using a <c>private static readonly</c> - /// variable is the most efficient because it is a run time constant - /// and can be heavily optimized by the JIT compiler. - /// </para> - /// <para> - /// Of course if you use a static readonly variable to - /// hold the enabled state of the logger then you cannot - /// change the enabled state at runtime to vary the logging - /// that is produced. You have to decide if you need absolute - /// speed or runtime flexibility. - /// </para> - /// </remarks> - /// <seealso cref="Debug(object)"/> - bool IsDebugEnabled { get; } - - /// <summary> - /// Checks if this logger is enabled for the <see cref="Level.Info"/> level. - /// </summary> - /// <value> - /// <c>true</c> if this logger is enabled for <see cref="Level.Info"/> events, <c>false</c> otherwise. - /// </value> - /// <remarks> - /// For more information see <see cref="ILog.IsDebugEnabled"/>. - /// </remarks> - /// <seealso cref="Info(object)"/> - /// <seealso cref="ILog.IsDebugEnabled"/> - bool IsInfoEnabled { get; } - - /// <summary> - /// Checks if this logger is enabled for the <see cref="Level.Warn"/> level. - /// </summary> - /// <value> - /// <c>true</c> if this logger is enabled for <see cref="Level.Warn"/> events, <c>false</c> otherwise. - /// </value> - /// <remarks> - /// For more information see <see cref="ILog.IsDebugEnabled"/>. - /// </remarks> - /// <seealso cref="Warn(object)"/> - /// <seealso cref="ILog.IsDebugEnabled"/> - bool IsWarnEnabled { get; } - - /// <summary> - /// Checks if this logger is enabled for the <see cref="Level.Error"/> level. - /// </summary> - /// <value> - /// <c>true</c> if this logger is enabled for <see cref="Level.Error"/> events, <c>false</c> otherwise. - /// </value> - /// <remarks> - /// For more information see <see cref="ILog.IsDebugEnabled"/>. - /// </remarks> - /// <seealso cref="Error(object)"/> - /// <seealso cref="ILog.IsDebugEnabled"/> - bool IsErrorEnabled { get; } - - /// <summary> - /// Checks if this logger is enabled for the <see cref="Level.Fatal"/> level. - /// </summary> - /// <value> - /// <c>true</c> if this logger is enabled for <see cref="Level.Fatal"/> events, <c>false</c> otherwise. - /// </value> - /// <remarks> - /// For more information see <see cref="ILog.IsDebugEnabled"/>. - /// </remarks> - /// <seealso cref="Fatal(object)"/> - /// <seealso cref="ILog.IsDebugEnabled"/> - bool IsFatalEnabled { get; } - } -} diff --git a/src/DotNetOpenAuth.Core/Loggers/Log4NetLogger.cs b/src/DotNetOpenAuth.Core/Loggers/Log4NetLogger.cs deleted file mode 100644 index 01da034..0000000 --- a/src/DotNetOpenAuth.Core/Loggers/Log4NetLogger.cs +++ /dev/null @@ -1,219 +0,0 @@ -// <auto-generated /> - -namespace DotNetOpenAuth.Loggers { - using System; - using System.Globalization; - using System.IO; - using System.Reflection; - - internal class Log4NetLogger : ILog { - private log4net.ILog log4netLogger; - - private Log4NetLogger(log4net.ILog logger) { - this.log4netLogger = logger; - } - - #region ILog Members - - public bool IsDebugEnabled { - get { return this.log4netLogger.IsDebugEnabled; } - } - - public bool IsInfoEnabled { - get { return this.log4netLogger.IsInfoEnabled; } - } - - public bool IsWarnEnabled { - get { return this.log4netLogger.IsWarnEnabled; } - } - - public bool IsErrorEnabled { - get { return this.log4netLogger.IsErrorEnabled; } - } - - public bool IsFatalEnabled { - get { return this.log4netLogger.IsFatalEnabled; } - } - - #endregion - - private static bool IsLog4NetPresent { - get { - try { - Assembly.Load("log4net"); - return true; - } catch (FileNotFoundException) { - return false; - } - } - } - - #region ILog methods - - public void Debug(object message) { - this.log4netLogger.Debug(message); - } - - public void Debug(object message, Exception exception) { - this.log4netLogger.Debug(message, exception); - } - - public void DebugFormat(string format, params object[] args) { - this.log4netLogger.DebugFormat(CultureInfo.InvariantCulture, format, args); - } - - public void DebugFormat(string format, object arg0) { - this.log4netLogger.DebugFormat(format, arg0); - } - - public void DebugFormat(string format, object arg0, object arg1) { - this.log4netLogger.DebugFormat(format, arg0, arg1); - } - - public void DebugFormat(string format, object arg0, object arg1, object arg2) { - this.log4netLogger.DebugFormat(format, arg0, arg1, arg2); - } - - public void DebugFormat(IFormatProvider provider, string format, params object[] args) { - this.log4netLogger.DebugFormat(provider, format, args); - } - - public void Info(object message) { - this.log4netLogger.Info(message); - } - - public void Info(object message, Exception exception) { - this.log4netLogger.Info(message, exception); - } - - public void InfoFormat(string format, params object[] args) { - this.log4netLogger.InfoFormat(CultureInfo.InvariantCulture, format, args); - } - - public void InfoFormat(string format, object arg0) { - this.log4netLogger.InfoFormat(format, arg0); - } - - public void InfoFormat(string format, object arg0, object arg1) { - this.log4netLogger.InfoFormat(format, arg0, arg1); - } - - public void InfoFormat(string format, object arg0, object arg1, object arg2) { - this.log4netLogger.InfoFormat(format, arg0, arg1, arg2); - } - - public void InfoFormat(IFormatProvider provider, string format, params object[] args) { - this.log4netLogger.InfoFormat(provider, format, args); - } - - public void Warn(object message) { - this.log4netLogger.Warn(message); - } - - public void Warn(object message, Exception exception) { - this.log4netLogger.Warn(message, exception); - } - - public void WarnFormat(string format, params object[] args) { - this.log4netLogger.WarnFormat(CultureInfo.InvariantCulture, format, args); - } - - public void WarnFormat(string format, object arg0) { - this.log4netLogger.WarnFormat(format, arg0); - } - - public void WarnFormat(string format, object arg0, object arg1) { - this.log4netLogger.WarnFormat(format, arg0, arg1); - } - - public void WarnFormat(string format, object arg0, object arg1, object arg2) { - this.log4netLogger.WarnFormat(format, arg0, arg1, arg2); - } - - public void WarnFormat(IFormatProvider provider, string format, params object[] args) { - this.log4netLogger.WarnFormat(provider, format, args); - } - - public void Error(object message) { - this.log4netLogger.Error(message); - } - - public void Error(object message, Exception exception) { - this.log4netLogger.Error(message, exception); - } - - public void ErrorFormat(string format, params object[] args) { - this.log4netLogger.ErrorFormat(CultureInfo.InvariantCulture, format, args); - } - - public void ErrorFormat(string format, object arg0) { - this.log4netLogger.ErrorFormat(format, arg0); - } - - public void ErrorFormat(string format, object arg0, object arg1) { - this.log4netLogger.ErrorFormat(format, arg0, arg1); - } - - public void ErrorFormat(string format, object arg0, object arg1, object arg2) { - this.log4netLogger.ErrorFormat(format, arg0, arg1, arg2); - } - - public void ErrorFormat(IFormatProvider provider, string format, params object[] args) { - this.log4netLogger.ErrorFormat(provider, format, args); - } - - public void Fatal(object message) { - this.log4netLogger.Fatal(message); - } - - public void Fatal(object message, Exception exception) { - this.log4netLogger.Fatal(message, exception); - } - - public void FatalFormat(string format, params object[] args) { - this.log4netLogger.FatalFormat(CultureInfo.InvariantCulture, format, args); - } - - public void FatalFormat(string format, object arg0) { - this.log4netLogger.FatalFormat(format, arg0); - } - - public void FatalFormat(string format, object arg0, object arg1) { - this.log4netLogger.FatalFormat(format, arg0, arg1); - } - - public void FatalFormat(string format, object arg0, object arg1, object arg2) { - this.log4netLogger.FatalFormat(format, arg0, arg1, arg2); - } - - public void FatalFormat(IFormatProvider provider, string format, params object[] args) { - this.log4netLogger.FatalFormat(provider, format, args); - } - - #endregion - - /// <summary> - /// Returns a new log4net logger if it exists, or returns null if the assembly cannot be found. - /// </summary> - /// <returns>The created <see cref="ILog"/> instance.</returns> - internal static ILog Initialize(string name) { - try { - return IsLog4NetPresent ? CreateLogger(name) : null; - } catch (FileLoadException) { // wrong log4net.dll version - return null; - } catch (TargetInvocationException) { // Thrown due to some security issues on .NET 4.5. - return null; - } catch (TypeLoadException) { // Thrown by mono (http://stackoverflow.com/questions/10805773/error-when-pushing-dotnetopenauth-to-staging-or-production-environment) - return null; - } - } - - /// <summary> - /// Creates the log4net.LogManager. Call ONLY after log4net.dll is known to be present. - /// </summary> - /// <returns>The created <see cref="ILog"/> instance.</returns> - private static ILog CreateLogger(string name) { - return new Log4NetLogger(log4net.LogManager.GetLogger(name)); - } - } -} diff --git a/src/DotNetOpenAuth.Core/Loggers/NLogLogger.cs b/src/DotNetOpenAuth.Core/Loggers/NLogLogger.cs deleted file mode 100644 index b5d883d..0000000 --- a/src/DotNetOpenAuth.Core/Loggers/NLogLogger.cs +++ /dev/null @@ -1,222 +0,0 @@ -// <auto-generated /> - -namespace DotNetOpenAuth.Loggers { - using System; - using System.Globalization; - using System.IO; - using System.Reflection; - - internal class NLogLogger : ILog { - private NLog.Logger nLogLogger; - - private NLogLogger(NLog.Logger logger) { - this.nLogLogger = logger; - } - - #region ILog Members - - public bool IsDebugEnabled { - get { return this.nLogLogger.IsDebugEnabled; } - } - - public bool IsInfoEnabled { - get { return this.nLogLogger.IsInfoEnabled; } - } - - public bool IsWarnEnabled { - get { return this.nLogLogger.IsWarnEnabled; } - } - - public bool IsErrorEnabled { - get { return this.nLogLogger.IsErrorEnabled; } - } - - public bool IsFatalEnabled { - get { return this.nLogLogger.IsFatalEnabled; } - } - - #endregion - - private static bool IsNLogPresent { - get { - try { - Assembly.Load("NLog"); - return true; - } catch (FileNotFoundException) { - return false; - } - } - } - - #region ILog methods - - public void Debug(object message) { - this.nLogLogger.Debug(message); - } - - public void Debug(object message, Exception exception) { - this.nLogLogger.DebugException(String.Format("{0}", message), exception); - } - - public void DebugFormat(string format, params object[] args) { - this.nLogLogger.Debug(CultureInfo.InvariantCulture, format, args); - } - - public void DebugFormat(string format, object arg0) { - this.nLogLogger.Debug(format, arg0); - } - - public void DebugFormat(string format, object arg0, object arg1) { - this.nLogLogger.Debug(format, arg0, arg1); - } - - public void DebugFormat(string format, object arg0, object arg1, object arg2) { - this.nLogLogger.Debug(format, arg0, arg1, arg2); - } - - public void DebugFormat(IFormatProvider provider, string format, params object[] args) { - this.nLogLogger.Debug(provider, format, args); - } - - public void Info(object message) { - this.nLogLogger.Info(message); - } - - public void Info(object message, Exception exception) { - this.nLogLogger.InfoException(String.Format("{0}", message), exception); - } - - public void InfoFormat(string format, params object[] args) { - this.nLogLogger.Info(CultureInfo.InvariantCulture, format, args); - } - - public void InfoFormat(string format, object arg0) { - this.nLogLogger.Info(format, arg0); - } - - public void InfoFormat(string format, object arg0, object arg1) { - this.nLogLogger.Info(format, arg0, arg1); - } - - public void InfoFormat(string format, object arg0, object arg1, object arg2) { - this.nLogLogger.Info(format, arg0, arg1, arg2); - } - - public void InfoFormat(IFormatProvider provider, string format, params object[] args) { - this.nLogLogger.Info(provider, format, args); - } - - public void Warn(object message) { - this.nLogLogger.Warn(message); - } - - public void Warn(object message, Exception exception) { - this.nLogLogger.Warn(String.Format("{0}", message), exception); - } - - public void WarnFormat(string format, params object[] args) { - this.nLogLogger.Warn(CultureInfo.InvariantCulture, format, args); - } - - public void WarnFormat(string format, object arg0) { - this.nLogLogger.Warn(format, arg0); - } - - public void WarnFormat(string format, object arg0, object arg1) { - this.nLogLogger.Warn(format, arg0, arg1); - } - - public void WarnFormat(string format, object arg0, object arg1, object arg2) { - this.nLogLogger.Warn(format, arg0, arg1, arg2); - } - - public void WarnFormat(IFormatProvider provider, string format, params object[] args) { - this.nLogLogger.Warn(provider, format, args); - } - - public void Error(object message) { - this.nLogLogger.Error(message); - } - - public void Error(object message, Exception exception) { - this.nLogLogger.Error(String.Format("{0}", message), exception); - } - - public void ErrorFormat(string format, params object[] args) { - this.nLogLogger.Error(CultureInfo.InvariantCulture, format, args); - } - - public void ErrorFormat(string format, object arg0) { - this.nLogLogger.Error(format, arg0); - } - - public void ErrorFormat(string format, object arg0, object arg1) { - this.nLogLogger.Error(format, arg0, arg1); - } - - public void ErrorFormat(string format, object arg0, object arg1, object arg2) { - this.nLogLogger.Error(format, arg0, arg1, arg2); - } - - public void ErrorFormat(IFormatProvider provider, string format, params object[] args) { - this.nLogLogger.Error(provider, format, args); - } - - public void Fatal(object message) { - this.nLogLogger.Fatal(message); - } - - public void Fatal(object message, Exception exception) { - this.nLogLogger.Fatal(String.Format("{0}", message), exception); - } - - public void FatalFormat(string format, params object[] args) { - this.nLogLogger.Fatal(CultureInfo.InvariantCulture, format, args); - } - - public void FatalFormat(string format, object arg0) { - this.nLogLogger.Fatal(format, arg0); - } - - public void FatalFormat(string format, object arg0, object arg1) { - this.nLogLogger.Fatal(format, arg0, arg1); - } - - public void FatalFormat(string format, object arg0, object arg1, object arg2) { - this.nLogLogger.Fatal(format, arg0, arg1, arg2); - } - - public void FatalFormat(IFormatProvider provider, string format, params object[] args) { - this.nLogLogger.Fatal(provider, format, args); - } - - #endregion - - /// <summary> - /// Returns a new NLog logger if it exists, or returns null if the assembly cannot be found. - /// </summary> - /// <returns>The created <see cref="ILog"/> instance.</returns> - internal static ILog Initialize(string name) { - try { - return IsNLogPresent ? CreateLogger(name) : null; - } catch (FileLoadException) { - // wrong NLog.dll version - return null; - } catch (TargetInvocationException) { - // Thrown due to some security issues on .NET 4.5. - return null; - } catch (TypeLoadException) { - // Thrown by mono (http://stackoverflow.com/questions/10805773/error-when-pushing-dotnetopenauth-to-staging-or-production-environment) - return null; - } - } - - /// <summary> - /// Creates the NLogLogger. Call ONLY after NLog.dll is known to be present. - /// </summary> - /// <returns>The created <see cref="ILog"/> instance.</returns> - private static ILog CreateLogger(string name) { - return new NLogLogger(NLog.LogManager.GetLogger(name)); - } - } -} diff --git a/src/DotNetOpenAuth.Core/Loggers/NoOpLogger.cs b/src/DotNetOpenAuth.Core/Loggers/NoOpLogger.cs deleted file mode 100644 index 7d1b37f..0000000 --- a/src/DotNetOpenAuth.Core/Loggers/NoOpLogger.cs +++ /dev/null @@ -1,159 +0,0 @@ -// <auto-generated /> - -namespace DotNetOpenAuth.Loggers { - using System; - - internal class NoOpLogger : ILog { - #region ILog Members - - public bool IsDebugEnabled { - get { return false; } - } - - public bool IsInfoEnabled { - get { return false; } - } - - public bool IsWarnEnabled { - get { return false; } - } - - public bool IsErrorEnabled { - get { return false; } - } - - public bool IsFatalEnabled { - get { return false; } - } - - public void Debug(object message) { - return; - } - - public void Debug(object message, Exception exception) { - return; - } - - public void DebugFormat(string format, params object[] args) { - return; - } - - public void DebugFormat(string format, object arg0) { - return; - } - - public void DebugFormat(string format, object arg0, object arg1) { - return; - } - - public void DebugFormat(string format, object arg0, object arg1, object arg2) { - return; - } - - public void Info(object message) { - return; - } - - public void Info(object message, Exception exception) { - return; - } - - public void InfoFormat(string format, params object[] args) { - return; - } - - public void InfoFormat(string format, object arg0) { - return; - } - - public void InfoFormat(string format, object arg0, object arg1) { - return; - } - - public void InfoFormat(string format, object arg0, object arg1, object arg2) { - return; - } - - public void Warn(object message) { - return; - } - - public void Warn(object message, Exception exception) { - return; - } - - public void WarnFormat(string format, params object[] args) { - return; - } - - public void WarnFormat(string format, object arg0) { - return; - } - - public void WarnFormat(string format, object arg0, object arg1) { - return; - } - - public void WarnFormat(string format, object arg0, object arg1, object arg2) { - return; - } - - public void Error(object message) { - return; - } - - public void Error(object message, Exception exception) { - return; - } - - public void ErrorFormat(string format, params object[] args) { - return; - } - - public void ErrorFormat(string format, object arg0) { - return; - } - - public void ErrorFormat(string format, object arg0, object arg1) { - return; - } - - public void ErrorFormat(string format, object arg0, object arg1, object arg2) { - return; - } - - public void Fatal(object message) { - return; - } - - public void Fatal(object message, Exception exception) { - return; - } - - public void FatalFormat(string format, params object[] args) { - return; - } - - public void FatalFormat(string format, object arg0) { - return; - } - - public void FatalFormat(string format, object arg0, object arg1) { - return; - } - - public void FatalFormat(string format, object arg0, object arg1, object arg2) { - return; - } - - #endregion - - /// <summary> - /// Returns a new logger that does nothing when invoked. - /// </summary> - /// <returns>The created <see cref="ILog"/> instance.</returns> - internal static ILog Initialize() { - return new NoOpLogger(); - } - } -} diff --git a/src/DotNetOpenAuth.Core/Loggers/TraceLogger.cs b/src/DotNetOpenAuth.Core/Loggers/TraceLogger.cs deleted file mode 100644 index 1b80c7d..0000000 --- a/src/DotNetOpenAuth.Core/Loggers/TraceLogger.cs +++ /dev/null @@ -1,357 +0,0 @@ -// <auto-generated /> - -namespace DotNetOpenAuth.Loggers { - using System; - using System.Diagnostics; - using System.Security; - using System.Security.Permissions; - - internal class TraceLogger : ILog { - private TraceSwitch traceSwitch; - - internal TraceLogger(string name) { - traceSwitch = new TraceSwitch(name, name + " Trace Switch"); - } - - #region ILog Properties - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public bool IsDebugEnabled { - get { return this.traceSwitch.TraceVerbose; } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public bool IsInfoEnabled { - get { return this.traceSwitch.TraceInfo; } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public bool IsWarnEnabled { - get { return this.traceSwitch.TraceWarning; } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public bool IsErrorEnabled { - get { return this.traceSwitch.TraceError; } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public bool IsFatalEnabled { - get { return this.traceSwitch.TraceError; } - } - - #endregion - - private static bool IsSufficientPermissionGranted { - get { - PermissionSet permissions = new PermissionSet(PermissionState.None); - permissions.AddPermission(new KeyContainerPermission(PermissionState.Unrestricted)); - permissions.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess)); - permissions.AddPermission(new RegistryPermission(PermissionState.Unrestricted)); - permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.UnmanagedCode | SecurityPermissionFlag.ControlThread)); - var file = new FileIOPermission(PermissionState.None); - file.AllFiles = FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read; - permissions.AddPermission(file); - try { - permissions.Demand(); - return true; - } catch (SecurityException) { - return false; - } - } - } - - #region ILog Methods - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void Debug(object message) { - if (this.IsDebugEnabled) { - Trace.TraceInformation(message.ToString()); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void Debug(object message, Exception exception) { - if (this.IsDebugEnabled) { - Trace.TraceInformation(message + ": " + exception.ToString()); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void DebugFormat(string format, params object[] args) { - if (this.IsDebugEnabled) { - Trace.TraceInformation(format, args); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void DebugFormat(string format, object arg0) { - if (this.IsDebugEnabled) { - Trace.TraceInformation(format, arg0); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void DebugFormat(string format, object arg0, object arg1) { - if (this.IsDebugEnabled) { - Trace.TraceInformation(format, arg0, arg1); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void DebugFormat(string format, object arg0, object arg1, object arg2) { - if (this.IsDebugEnabled) { - Trace.TraceInformation(format, arg0, arg1, arg2); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void Info(object message) { - if (this.IsInfoEnabled) { - Trace.TraceInformation(message.ToString()); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void Info(object message, Exception exception) { - if (this.IsInfoEnabled) { - Trace.TraceInformation(message + ": " + exception.ToString()); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void InfoFormat(string format, params object[] args) { - if (this.IsInfoEnabled) { - Trace.TraceInformation(format, args); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void InfoFormat(string format, object arg0) { - if (this.IsInfoEnabled) { - Trace.TraceInformation(format, arg0); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void InfoFormat(string format, object arg0, object arg1) { - if (this.IsInfoEnabled) { - Trace.TraceInformation(format, arg0, arg1); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void InfoFormat(string format, object arg0, object arg1, object arg2) { - if (this.IsInfoEnabled) { - Trace.TraceInformation(format, arg0, arg1, arg2); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void Warn(object message) { - if (this.IsWarnEnabled) { - Trace.TraceWarning(message.ToString()); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void Warn(object message, Exception exception) { - if (this.IsWarnEnabled) { - Trace.TraceWarning(message + ": " + exception.ToString()); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void WarnFormat(string format, params object[] args) { - if (this.IsWarnEnabled) { - Trace.TraceWarning(format, args); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void WarnFormat(string format, object arg0) { - if (this.IsWarnEnabled) { - Trace.TraceWarning(format, arg0); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void WarnFormat(string format, object arg0, object arg1) { - if (this.IsWarnEnabled) { - Trace.TraceWarning(format, arg0, arg1); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void WarnFormat(string format, object arg0, object arg1, object arg2) { - if (this.IsWarnEnabled) { - Trace.TraceWarning(format, arg0, arg1, arg2); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void Error(object message) { - if (this.IsErrorEnabled) { - Trace.TraceError(message.ToString()); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void Error(object message, Exception exception) { - if (this.IsErrorEnabled) { - Trace.TraceError(message + ": " + exception.ToString()); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void ErrorFormat(string format, params object[] args) { - if (this.IsErrorEnabled) { - Trace.TraceError(format, args); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void ErrorFormat(string format, object arg0) { - if (this.IsErrorEnabled) { - Trace.TraceError(format, arg0); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void ErrorFormat(string format, object arg0, object arg1) { - if (this.IsErrorEnabled) { - Trace.TraceError(format, arg0, arg1); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void ErrorFormat(string format, object arg0, object arg1, object arg2) { - if (this.IsErrorEnabled) { - Trace.TraceError(format, arg0, arg1, arg2); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void Fatal(object message) { - if (this.IsFatalEnabled) { - Trace.TraceError(message.ToString()); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void Fatal(object message, Exception exception) { - if (this.IsFatalEnabled) { - Trace.TraceError(message + ": " + exception.ToString()); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void FatalFormat(string format, params object[] args) { - if (this.IsFatalEnabled) { - Trace.TraceError(format, args); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void FatalFormat(string format, object arg0) { - if (this.IsFatalEnabled) { - Trace.TraceError(format, arg0); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void FatalFormat(string format, object arg0, object arg1) { - if (this.IsFatalEnabled) { - Trace.TraceError(format, arg0, arg1); - } - } - - /// <summary> - /// See <see cref="ILog"/>. - /// </summary> - public void FatalFormat(string format, object arg0, object arg1, object arg2) { - if (this.IsFatalEnabled) { - Trace.TraceError(format, arg0, arg1, arg2); - } - } - - #endregion - - /// <summary> - /// Returns a new logger that uses the <see cref="System.Diagnostics.Trace"/> class - /// if sufficient CAS permissions are granted to use it, otherwise returns false. - /// </summary> - /// <returns>The created <see cref="ILog"/> instance.</returns> - internal static ILog Initialize(string name) { - return IsSufficientPermissionGranted ? new TraceLogger(name) : null; - } - } -} diff --git a/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs b/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs index 65c7882..6044d0a 100644 --- a/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs +++ b/src/DotNetOpenAuth.Core/Messaging/Bindings/StandardReplayProtectionBindingElement.cs @@ -9,6 +9,9 @@ namespace DotNetOpenAuth.Messaging.Bindings { using System.Diagnostics; using System.Threading; using System.Threading.Tasks; + + using DotNetOpenAuth.Logging; + using Validation; /// <summary> diff --git a/src/DotNetOpenAuth.Core/Messaging/Channel.cs b/src/DotNetOpenAuth.Core/Messaging/Channel.cs index cc61b25..b754035 100644 --- a/src/DotNetOpenAuth.Core/Messaging/Channel.cs +++ b/src/DotNetOpenAuth.Core/Messaging/Channel.cs @@ -27,6 +27,8 @@ namespace DotNetOpenAuth.Messaging { using System.Threading.Tasks; using System.Web; using System.Xml; + + using DotNetOpenAuth.Logging; using DotNetOpenAuth.Messaging.Reflection; using Validation; @@ -395,7 +397,7 @@ namespace DotNetOpenAuth.Messaging { public async Task<IDirectedProtocolMessage> ReadFromRequestAsync(HttpRequestMessage httpRequest, CancellationToken cancellationToken) { Requires.NotNull(httpRequest, "httpRequest"); - if (Logger.Channel.IsInfoEnabled && httpRequest.RequestUri != null) { + if (Logger.Channel.IsInfoEnabled() && httpRequest.RequestUri != null) { Logger.Channel.InfoFormat("Scanning incoming request for messages: {0}", httpRequest.RequestUri.AbsoluteUri); } IDirectedProtocolMessage requestMessage = await this.ReadFromRequestCoreAsync(httpRequest, cancellationToken); @@ -1034,7 +1036,7 @@ namespace DotNetOpenAuth.Messaging { this.OutgoingMessageFilter(message); } - if (Logger.Channel.IsInfoEnabled) { + if (Logger.Channel.IsInfoEnabled()) { var directedMessage = message as IDirectedProtocolMessage; string recipient = (directedMessage != null && directedMessage.Recipient != null) ? directedMessage.Recipient.AbsoluteUri : "<response>"; var messageAccessor = this.MessageDescriptions.GetAccessor(message); @@ -1173,7 +1175,7 @@ namespace DotNetOpenAuth.Messaging { protected virtual async Task ProcessIncomingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) { Requires.NotNull(message, "message"); - if (Logger.Channel.IsInfoEnabled) { + if (Logger.Channel.IsInfoEnabled()) { var messageAccessor = this.MessageDescriptions.GetAccessor(message, true); Logger.Channel.InfoFormat( "Processing incoming {0} ({1}) message:{2}{3}", @@ -1223,7 +1225,7 @@ namespace DotNetOpenAuth.Messaging { eventedMessage.OnReceiving(); } - if (Logger.Channel.IsDebugEnabled) { + if (Logger.Channel.IsDebugEnabled()) { var messageAccessor = this.MessageDescriptions.GetAccessor(message); Logger.Channel.DebugFormat( "After binding element processing, the received {0} ({1}) message is: {2}{3}", diff --git a/src/DotNetOpenAuth.Core/Messaging/DataBagFormatterBase.cs b/src/DotNetOpenAuth.Core/Messaging/DataBagFormatterBase.cs index 210a95e..e78c8b1 100644 --- a/src/DotNetOpenAuth.Core/Messaging/DataBagFormatterBase.cs +++ b/src/DotNetOpenAuth.Core/Messaging/DataBagFormatterBase.cs @@ -13,6 +13,8 @@ namespace DotNetOpenAuth.Messaging { using System.Security.Cryptography; using System.Text; using System.Web; + + using DotNetOpenAuth.Logging; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.Messaging.Reflection; diff --git a/src/DotNetOpenAuth.Core/Messaging/ErrorUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/ErrorUtilities.cs index 71c904b..abda04f 100644 --- a/src/DotNetOpenAuth.Core/Messaging/ErrorUtilities.cs +++ b/src/DotNetOpenAuth.Core/Messaging/ErrorUtilities.cs @@ -11,6 +11,9 @@ namespace DotNetOpenAuth.Messaging { using System.Diagnostics.Contracts; using System.Globalization; using System.Web; + + using DotNetOpenAuth.Logging; + using Validation; /// <summary> @@ -186,7 +189,7 @@ namespace DotNetOpenAuth.Messaging { Assumes.True(unformattedMessage != null); if (!condition) { var exception = new ProtocolException(string.Format(CultureInfo.CurrentCulture, unformattedMessage, args)); - if (Logger.Messaging.IsErrorEnabled) { + if (Logger.Messaging.IsErrorEnabled()) { Logger.Messaging.Error( string.Format( CultureInfo.CurrentCulture, diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs index 7be618c..c14e15b 100644 --- a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs +++ b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs @@ -25,6 +25,8 @@ namespace DotNetOpenAuth.Messaging { using System.Threading.Tasks; using System.Web; using System.Xml; + + using DotNetOpenAuth.Logging; using DotNetOpenAuth.Messaging.Bindings; using DotNetOpenAuth.Messaging.Reflection; using Validation; diff --git a/src/DotNetOpenAuth.Core/Messaging/Reflection/MessageDescription.cs b/src/DotNetOpenAuth.Core/Messaging/Reflection/MessageDescription.cs index cd04e1d..d6e5add 100644 --- a/src/DotNetOpenAuth.Core/Messaging/Reflection/MessageDescription.cs +++ b/src/DotNetOpenAuth.Core/Messaging/Reflection/MessageDescription.cs @@ -12,6 +12,9 @@ namespace DotNetOpenAuth.Messaging.Reflection { using System.Globalization; using System.Linq; using System.Reflection; + + using DotNetOpenAuth.Logging; + using Validation; /// <summary> diff --git a/src/DotNetOpenAuth.Core/Messaging/StandardMessageFactory.cs b/src/DotNetOpenAuth.Core/Messaging/StandardMessageFactory.cs index fd35e5f..006c798 100644 --- a/src/DotNetOpenAuth.Core/Messaging/StandardMessageFactory.cs +++ b/src/DotNetOpenAuth.Core/Messaging/StandardMessageFactory.cs @@ -10,6 +10,8 @@ namespace DotNetOpenAuth.Messaging { using System.Linq; using System.Reflection; using System.Text; + + using DotNetOpenAuth.Logging; using DotNetOpenAuth.Messaging.Reflection; using Validation; @@ -149,7 +151,7 @@ namespace DotNetOpenAuth.Messaging { .CacheGeneratedResults(); var match = matches.FirstOrDefault(); if (match != null) { - if (Logger.Messaging.IsWarnEnabled && matches.Count() > 1) { + if (Logger.Messaging.IsWarnEnabled() && matches.Count() > 1) { Logger.Messaging.WarnFormat( "Multiple message types seemed to fit the incoming data: {0}", matches.ToStringDeferred()); @@ -186,7 +188,7 @@ namespace DotNetOpenAuth.Messaging { select message).CacheGeneratedResults(); var match = matches.FirstOrDefault(); if (match != null) { - if (Logger.Messaging.IsWarnEnabled && matches.Count() > 1) { + if (Logger.Messaging.IsWarnEnabled() && matches.Count() > 1) { Logger.Messaging.WarnFormat( "Multiple message types seemed to fit the incoming data: {0}", matches.ToStringDeferred()); diff --git a/src/DotNetOpenAuth.Core/Reporting.cs b/src/DotNetOpenAuth.Core/Reporting.cs index 432a833..4d21c38 100644 --- a/src/DotNetOpenAuth.Core/Reporting.cs +++ b/src/DotNetOpenAuth.Core/Reporting.cs @@ -23,6 +23,7 @@ namespace DotNetOpenAuth { using System.Threading.Tasks; using System.Web; using DotNetOpenAuth.Configuration; + using DotNetOpenAuth.Logging; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.Messaging.Bindings; using Validation; @@ -361,7 +362,7 @@ namespace DotNetOpenAuth { // This is supposed to be as low-risk as possible, so if it fails, just disable reporting // and avoid rethrowing. broken = true; - Logger.Library.Error("Error while trying to initialize reporting.", e); + Logger.Library.ErrorException("Error while trying to initialize reporting.", e); } } } @@ -474,9 +475,9 @@ namespace DotNetOpenAuth { return true; } catch (ProtocolException ex) { - Logger.Library.Error("Unable to submit statistical report due to an HTTP error.", ex); + Logger.Library.ErrorException("Unable to submit statistical report due to an HTTP error.", ex); } catch (FileNotFoundException ex) { - Logger.Library.Error("Unable to submit statistical report because the report file is missing.", ex); + Logger.Library.ErrorException("Unable to submit statistical report because the report file is missing.", ex); } return false; diff --git a/src/DotNetOpenAuth.Core/packages.config b/src/DotNetOpenAuth.Core/packages.config index 0364828..b1c7f74 100644 --- a/src/DotNetOpenAuth.Core/packages.config +++ b/src/DotNetOpenAuth.Core/packages.config @@ -1,9 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="log4net" version="2.0.2" targetFramework="net45" /> + <package id="LibLog" version="2.0.1" targetFramework="net45" developmentDependency="true" /> <package id="Microsoft.Bcl" version="1.1.3" targetFramework="net45" /> <package id="Microsoft.Bcl.Build" version="1.0.10" targetFramework="net45" /> <package id="Microsoft.Net.Http" version="2.2.15" targetFramework="net45" /> - <package id="NLog" version="2.1.0" targetFramework="net45" /> <package id="Validation" version="2.0.2.13022" targetFramework="net45" /> </packages>
\ No newline at end of file |