コード例 #1
0
        public static mel.LogLevel ToMsLogLevel(this cl.LogLevel logLevel)
        {
            switch (logLevel)
            {
            case cl.LogLevel.All:
                return(mel.LogLevel.Trace);

            case cl.LogLevel.Debug:
                return(mel.LogLevel.Debug);

            case cl.LogLevel.Error:
                return(mel.LogLevel.Error);

            case cl.LogLevel.Fatal:
                return(mel.LogLevel.Critical);

            case cl.LogLevel.Info:
                return(mel.LogLevel.Information);

            case cl.LogLevel.Off:
                return(mel.LogLevel.None);

            case cl.LogLevel.Trace:
                return(mel.LogLevel.Trace);

            case cl.LogLevel.Warn:
                return(mel.LogLevel.Warning);

            default:
                return(mel.LogLevel.None);
            }
        }
コード例 #2
0
        protected override void WriteInternal(Common.Logging.LogLevel level, object message, Exception exception)
        {
            switch (level)
            {
            case LogLevel.Info:
                MainForm.LogMessageToFile(message.ToString());
                break;

            case LogLevel.Warn:
                MainForm.LogWarningToFile(message.ToString());
                break;

            case LogLevel.Error:
                if (exception != null)
                {
                    MainForm.LogExceptionToFile(message.ToString(), exception);
                }
                else
                {
                    MainForm.LogErrorToFile(message.ToString());
                }
                break;

            default:
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }
                break;
            }
        }
コード例 #3
0
 private Action <CapturingLoggerEvent> ExpectEvent(string loggerName,
                                                   Common.Logging.LogLevel level, string message)
 {
     return(e =>
     {
         Assert.Equal(level, e.Level);
         Assert.Equal(loggerName, e.Source.Name);
         Assert.Equal(message, e.RenderedMessage);
     });
 }
コード例 #4
0
        bool IsAnnoyingMessage(CL.LogLevel level, object message)
        {
            var messageString = message.ToString();

            return
                (messageString.StartsWith("ConnectionAndTransactionHolder passed to RollbackConnection was null, ignoring") ||
                 (level == CL.LogLevel.Info &&
                  (
                      (messageString.StartsWith("ClusterManager: detected") &&
                       messageString.EndsWith("failed or restarted instances."))
                      ||
                      (messageString.StartsWith("ClusterManager: Scanning for instance") &&
                       messageString.EndsWith("failed in-progress jobs.")))));
        }
コード例 #5
0
        protected override void WriteInternal(CL.LogLevel level, object message, Exception exception)
        {
            if (IsAnnoyingMessage(level, message))
            {
                level = CL.LogLevel.Trace;
            }

            string displayString;

            if (exception != null)
            {
                displayString = string.Format("{0}: Exception: {1}", message.ToString(), exception.ToString());
            }
            else
            {
                displayString = message.ToString();
            }

            switch (level)
            {
            case CL.LogLevel.Error:
            case CL.LogLevel.Fatal:
                EventLog.Application.WriteError(displayString);
                break;

            case CL.LogLevel.Info:

                EventLog.Application.WriteInformation(displayString);
                break;

            case CL.LogLevel.Warn:
                EventLog.Application.WriteWarning(displayString);
                break;

            default:
                EventLog.Application.WriteTrace(displayString);
                break;
            }
        }
コード例 #6
0
        public static void LogEx(this Common.Logging.ILog log, Common.Logging.LogLevel level, Action <TraceRecord> traceAction, [CallerMemberName] string member = "", [CallerLineNumber] int line = 0)
        {
            // Check if this log level is enabled
            if (level == LogLevel.Trace && log.IsTraceEnabled == false ||
                level == LogLevel.Debug && log.IsDebugEnabled == false ||
                level == LogLevel.Info && (log.IsInfoEnabled == false) ||
                level == LogLevel.Warn && (log.IsWarnEnabled == false) ||
                level == LogLevel.Error && (log.IsErrorEnabled == false) ||
                level == LogLevel.Fatal && (log.IsFatalEnabled == false))
            {
                return;
            }

            TraceRecord tr = new TraceRecord()
            {
                Level = level
            };

            traceAction(tr);
            string message = String.Format("{0}() line {1}: {2}.{3}", member, line, tr.Message, (tr.Data != null) ? Newtonsoft.Json.JsonConvert.SerializeObject(tr.Data) : "");

            switch (level)
            {
            case LogLevel.Trace: log.Trace(message, tr.Exception); break;

            case LogLevel.Debug: log.Debug(message, tr.Exception); break;

            case LogLevel.Error: log.Error(message, tr.Exception); break;

            case LogLevel.Fatal: log.Fatal(message, tr.Exception); break;

            case LogLevel.Info: log.Info(message, tr.Exception); break;

            case LogLevel.Warn: log.Warn(message, tr.Exception); break;
            }
        }
コード例 #7
0
 protected override ILog CreateLogger(string name, Common.Logging.LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat)
 {
     return(new ConsoleOutLogger(name, level, showLevel, showDateTime, showLogName, dateTimeFormat));
 }
コード例 #8
0
 /// <summary>
 /// Creates a new <see cref="Log"/> instance.
 /// </summary>
 protected override ILog CreateLogger(string name, LogLevel level, bool showLevel, bool showDateTime, bool showLogName, string dateTimeFormat)
 {
     ILog log = new Log(name, level, showLevel, showDateTime, showLogName, dateTimeFormat, this);
     return log;
 }