Exemplo n.º 1
0
        protected override void WriteFilteredEvent(LogEvent logEvent)
        {
            string message = null;

            if (_EventFormatter != null)
            {
                message = _EventFormatter.Format(logEvent);
            }
            else
            {
                message = logEvent.EventName;
            }

            if (message != null && message.Length > 32000)
            {
                int startIndex = 0;
                int partCnt    = 1;
                while (startIndex < message.Length)
                {
                    int partSize = Math.Min(32000, message.Length - startIndex);
                    _Log.WriteEntry($"Split Event, Part {partCnt.ToString()}" + Environment.NewLine + message.Substring(startIndex, partSize), LogEventToWindowsEventType(logEvent), logEvent.GetPropertyOrDefault("EventId", 0), logEvent.GetPropertyOrDefault <short>("CategoryId", LogEventToWindowsEventCategory(logEvent)), logEvent.GetPropertyOrDefault <byte[]>("RawData", null));
                    startIndex += partSize;
                    partCnt++;
                }
            }
            else
            {
                _Log.WriteEntry(message, LogEventToWindowsEventType(logEvent), logEvent.GetPropertyOrDefault("EventId", 0), logEvent.GetPropertyOrDefault <short>("CategoryId", LogEventToWindowsEventCategory(logEvent)), logEvent.GetPropertyOrDefault <byte[]>("RawData", null));
            }
        }
Exemplo n.º 2
0
        protected override void WriteFilteredEvent(LogEvent logEvent)
        {
            switch (logEvent.EventSeverity)
            {
            case LogEventSeverity.Information:
                System.Diagnostics.Trace.TraceInformation(_LogEventFormatter.Format(logEvent));
                break;

            case LogEventSeverity.Error:
                System.Diagnostics.Trace.TraceError(_LogEventFormatter.Format(logEvent));
                break;

            case LogEventSeverity.Warning:
                System.Diagnostics.Trace.TraceWarning(_LogEventFormatter.Format(logEvent));
                break;

            default:
                System.Diagnostics.Trace.TraceWarning(_LogEventFormatter.Format(logEvent), logEvent.EventSeverity.ToString());
                break;
            }
        }
        protected override void Flush(T[] logEvents)
        {
            if (logEvents.Length == 0)
            {
                return;
            }

            var path = _pathFactory();

            var directoryPath = Path.GetDirectoryName(path);

            if (directoryPath == null)
            {
                return;
            }

            _fileSystem.CreateDirectory(directoryPath);

            var builder = new StringBuilder();

            foreach (var logEvent in logEvents)
            {
                builder.AppendLine(_formatter.Format(logEvent));
            }

            while (true)
            {
                try
                {
                    _fileSystem.AppendAllText(path, builder.ToString());
                    return;
                }
                catch (Exception ex)
                {
                    Logger.Exception(ex);
                }

                Thread.Sleep(1000);
            }
        }
Exemplo n.º 4
0
        protected override void WriteFilteredEvent(LogEvent logEvent)
        {
            var writer = logEvent.EventSeverity >= LogEventSeverity.Error ? Console.Error : Console.Out;

            if (_LogEventFormatter != null)
            {
                Console.ForegroundColor = GetConsoleColor(logEvent.EventSeverity);
                writer.Write(_LogEventFormatter.Format(logEvent) + Environment.NewLine);
                Console.ResetColor();
            }
            else
            {
                writer.Write("[" + logEvent.DateTime.ToString("G") + "] ");
                Console.ForegroundColor = GetConsoleColor(logEvent.EventSeverity);
                writer.Write("[" + logEvent.EventSeverity.ToString() + "] ");
                Console.ResetColor();
                writer.Write("[" + logEvent.EventType.ToString() + "] ");
                writer.Write("[" + logEvent.Source + "] ");
                writer.Write("[" + logEvent.SourceMethod + "] ");
                writer.Write(logEvent.EventName);
                writer.Write(Environment.NewLine);
            }
        }
Exemplo n.º 5
0
 protected override void WriteFilteredEvent(LogEvent logEvent)
 {
     _Writer.Write(_LogEventFormatter.Format(logEvent));
 }
 public virtual void Log(T logEvent)
 {
     Console.Out.WriteLine(_formatter.Format(logEvent));
 }
Exemplo n.º 7
0
 protected override void WriteFilteredEvent(LogEvent logEvent)
 {
     System.Diagnostics.Debug.WriteLine(_LogEventFormatter.Format(logEvent), logEvent.EventType.ToString());
 }