Пример #1
0
 protected override void TraceFileOnly(TracingLevel level, string format, params object[] args)
 {
     try
     {
         if (level >= TracingSettings.Level)
         {
             string message = string.Empty;
             try
             {
                 message = args.Length == 0 ? format : string.Format(format ?? string.Empty, args);
                 TracingManager.AddTraceItem(new TraceItem(_logger, level, null, message));
             }
             catch (System.Exception ex)
             {
                 if (level < TracingLevel.Warn)
                 {
                     level = TracingLevel.Warn;
                 }
                 message = string.Concat("tracing formatting error: [", args.Length, "] ", format ?? string.Empty);
                 TracingManager.AddTraceItem(new TraceItem(_logger, level, ex, message));
             }
         }
     }
     catch
     {
         // mute everything...
     }
 }
Пример #2
0
        protected override void Trace(TracingLevel level, Exception error, string format, object[] args, ConsoleColor color = ConsoleColor.Gray)
        {
            try
            {
                string message = ((args == null || args.Length == 0) ? format : string.Format(format ?? string.Empty, args));
                #region Output message to Console.

                switch (level)
                {
                case TracingLevel.Debug:
                    Console.ForegroundColor = color;
                    Console.WriteLine(message);
                    Console.ForegroundColor = ConsoleColor.Gray;
                    break;

                case TracingLevel.Warn:
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine(message);
                    Console.ForegroundColor = ConsoleColor.Gray;
                    break;

                case TracingLevel.Error:
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine(message);
                    Console.ForegroundColor = ConsoleColor.Gray;
                    break;

                case TracingLevel.Crtitical:
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(message);
                    Console.ForegroundColor = ConsoleColor.Gray;
                    break;
                }

                #endregion
                if (level >= TracingSettings.Level)
                {
                    TracingManager.AddTraceItem(new TraceItem(_logger, level, error, message));
                    if (TracingManager.NotificationHandler != null)
                    {
                        TracingManager.NotificationHandler.Handle(level, error, message, _logger);
                    }
                }
            }
            catch
            {
                // mute everything...
            }
        }