csharp log4net记录器扩展

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp log4net记录器扩展相关的知识,希望对你有一定的参考价值。

using System;
using System.Reflection;

using log4net;

namespace Extensions
{
    public static class LogExtensions
    {
        public static void RecursiveLogError(this ILog logger, Exception exception)
        {
            if (logger == null) throw new ArgumentNullException("logger");
            if (exception == null) throw new ArgumentNullException("exception");

            logger.Error(exception.Message + "\n" + exception.StackTrace, exception);

            if (exception.InnerException != null)
            {
                RecursiveLogError(logger, exception.InnerException);
            }

            var typeLoadException = exception as ReflectionTypeLoadException;
            if (typeLoadException == null) return;

            foreach (var loaderException in typeLoadException.LoaderExceptions)
                RecursiveLogError(logger, loaderException);
        }
    }
}

以上是关于csharp log4net记录器扩展的主要内容,如果未能解决你的问题,请参考以下文章