protected override void OnTraceReceived(TraceMessage message) { try { object syncRoot = _lockTable[_filename]; lock (syncRoot) { string directory = Path.GetDirectoryName(_filename); if(!string.IsNullOrWhiteSpace(directory)) FileSystemHelper.EnsureDirectoryExists(directory); using (StreamWriter writer = new StreamWriter(_filename, true)) { writer.WriteLine(message); writer.Flush(); } } } catch (Exception e) { Dispose(true); Tracer.Error(e); } }
protected override void OnTraceReceived(TraceMessage message) { ConsoleColor color = ConsoleColor.Gray; switch (message.Type) { case TraceLevels.Info: color = ConsoleColor.White; break; case TraceLevels.Warning: color = ConsoleColor.Yellow; break; case TraceLevels.Error: case TraceLevels.Fatal: color = ConsoleColor.Red; break; default: break; } ConsoleHelper.PushColor(color); Console.WriteLine(message); ConsoleHelper.PopColor(); }
public static void Trace(TraceLevels type, string message, params object[] args) { lock (_syncRoot) { if (TraceReceived != null) { if (args.Length > 0) { message = string.Format(message, args); } TraceMessage traceMessage = new TraceMessage(type, DateTime.UtcNow, message, string.IsNullOrEmpty(Thread.CurrentThread.Name) ? Thread.CurrentThread.ManagedThreadId.ToString() : Thread.CurrentThread.Name); TraceReceived(new TraceMessageEventArgs(traceMessage)); } } }
public TraceMessageEventArgs(TraceMessage traceMessage) { Guard.AssertIsNotNull(traceMessage, "traceMessage"); TraceMessage = traceMessage; }
protected override void OnTraceReceived(TraceMessage message) { _console.WriteLine("{0}: {1}", message.Type, message.Message); }
public static void Trace(TraceLevels type, string message, params object[] args) { lock (_syncRoot) { if (TraceReceived != null) { if (args.Length > 0) { message = string.Format(message, args); } TraceMessage traceMessage = new TraceMessage( type, DateTime.UtcNow, message, string.IsNullOrEmpty(Thread.CurrentThread.Name) ? Thread.CurrentThread.ManagedThreadId.ToString() : Thread.CurrentThread.Name); TraceReceived(new TraceMessageEventArgs(traceMessage)); } } }
protected override void OnTraceReceived(TraceMessage message) { Debug.WriteLine(message); }