Esempio n. 1
0
 private static void AssertLogLevelEnabled(ILoggerBase logger, LogLevel[] expectedLogLevels)
 {
     for (int i = LogLevel.MinLevel.Ordinal; i <= LogLevel.MaxLevel.Ordinal; ++i)
     {
         var logLevel = LogLevel.FromOrdinal(i);
         if (expectedLogLevels.Contains(logLevel))
         {
             Assert.True(logger.IsEnabled(logLevel), $"{logLevel} expected as true");
         }
         else
         {
             Assert.False(logger.IsEnabled(logLevel), $"{logLevel} expected as false");
         }
     }
 }
        public object Invoke(IMethodInvocation invocation)
        {
            ILoggerBase logger = invocation.Target as ILoggerBase;

            if (logger != null)
            {
                StringBuilder sb = null;
                if (logger.LOG.IsDebugEnabled)
                {
                    logger.LOG.AppendMethodEnterString(ref sb, invocation.Method, invocation.Arguments);
                    logger.LOG.Debug("$$ METHOD_ENTER: " + sb.ToString());
                }
                try
                {
                    // INVOKE:
                    object returnValue = invocation.Proceed();

                    if (logger.LOG.IsDebugEnabled && (invocation.Method.ReturnParameter != null) &&
                        (invocation.Method.ReturnParameter.ParameterType != typeof(void)))
                    {
                        if (sb != null)
                        {
                            sb.Length = 0;
                        }
                        logger.LOG.AppendMethodReturnValueString(ref sb, invocation.Method, returnValue);
                        logger.LOG.Debug("$$ METHOD_EXIT: " + sb.ToString());
                    }
                    return(returnValue);
                }
                catch (Exception e)
                {
                    if (logger.LOG.IsErrorEnabled)
                    {
                        if (sb != null)
                        {
                            sb.Length = 0;
                        }
                        logger.LOG.AppendMethodErrorString(ref sb, invocation.Method, e);
                        logger.LOG.Error("$$ METHOD_ERROR: " + sb.ToString());
                    }
                    throw;
                }
            }
            else
            {
                return(invocation.Proceed());
            }
        }
Esempio n. 3
0
 private static void AssertLogLevelEnabled(ILoggerBase logger, LogLevel expectedLogLevel)
 {
     AssertLogLevelEnabled(logger, new[] { expectedLogLevel });
 }