void Colorize( TraceEventType eventType ) { if (eventType.HasFlag( TraceEventType.Critical )) { Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Red; } else if (eventType.HasFlag( TraceEventType.Error )) { Console.ForegroundColor = ConsoleColor.Red; Console.BackgroundColor = ConsoleColor.Black; } else if (eventType.HasFlag( TraceEventType.Warning )) { Console.ForegroundColor = ConsoleColor.Yellow; Console.BackgroundColor = ConsoleColor.Black; } else if (eventType.HasFlag( TraceEventType.Information )) { Console.ForegroundColor = ConsoleColor.Gray; Console.BackgroundColor = ConsoleColor.Black; } else if (eventType.HasFlag( TraceEventType.Verbose )) { Console.ForegroundColor = ConsoleColor.DarkGray; Console.BackgroundColor = ConsoleColor.Blue; } else { Console.ForegroundColor = ConsoleColor.Gray; Console.BackgroundColor = ConsoleColor.Black; } }
/// <summary>檢查此訊息是否需要寫入記錄檔,依照 <see cref="TraceListener.Filter"/> 設定為準</summary> /// <param name="source"><see cref="SourceFilter.Source"/></param> /// <param name="eventType"><see cref="EventTypeFilter.EventType"/></param> /// <returns>(True)需要寫入記錄檔 (False)不須寫入</returns> private bool IsNecessary(string source, TraceEventType eventType) { bool necessary = false; /* 判斷 Filter 是否為 EventTypeFilter */ EventTypeFilter evnFilter = Filter as EventTypeFilter; if (evnFilter != null) { /* 因 SourceLevels 與 TraceEventType 兩個 Enum 數值不同,故用單一比較 */ SourceLevels srcLv = evnFilter.EventType; necessary = srcLv.HasFlag(SourceLevels.All) || (srcLv.HasFlag(SourceLevels.Error) && eventType.HasFlag(TraceEventType.Error)) || (srcLv.HasFlag(SourceLevels.Information) && eventType.HasFlag(TraceEventType.Information)) || (srcLv.HasFlag(SourceLevels.Warning) && eventType.HasFlag(TraceEventType.Warning)) || (srcLv.HasFlag(SourceLevels.Critical) && eventType.HasFlag(TraceEventType.Critical)) || (srcLv.HasFlag(SourceLevels.Verbose) && eventType.HasFlag(TraceEventType.Verbose)); } else { /* 檢查是否為 SourceFilter */ SourceFilter srcFilter = Filter as SourceFilter; if (srcFilter != null) { necessary = srcFilter.Source == source; } } return(necessary); }
TextWriter GetWriter(TraceEventType eventType) { if (eventType.HasFlag(TraceEventType.Error) || eventType.HasFlag(TraceEventType.Warning)) { return(Console.Error); } else { return(Console.Out); } }
private bool CallStackAdder(TraceEventType eventType) { if (TraceOutputOptions.HasFlag(TraceOptions.Callstack)) { return(false); } bool importantEvent = eventType.HasFlag(TraceEventType.Error) || eventType.HasFlag(TraceEventType.Critical); if (!importantEvent) { return(false); } TraceOutputOptions |= TraceOptions.Callstack; return(true); }
void Colorize(TraceEventType eventType) { if (eventType.HasFlag(TraceEventType.Critical)) { Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.Red; } else if (eventType.HasFlag(TraceEventType.Error)) { Console.ForegroundColor = ConsoleColor.Red; Console.BackgroundColor = ConsoleColor.Black; } else if (eventType.HasFlag(TraceEventType.Warning)) { Console.ForegroundColor = ConsoleColor.Yellow; Console.BackgroundColor = ConsoleColor.Black; } else if (eventType.HasFlag(TraceEventType.Information)) { Console.ForegroundColor = ConsoleColor.Gray; Console.BackgroundColor = ConsoleColor.Black; } else if (eventType.HasFlag(TraceEventType.Verbose)) { Console.ForegroundColor = ConsoleColor.DarkGray; Console.BackgroundColor = ConsoleColor.Blue; } else { Console.ForegroundColor = ConsoleColor.Gray; Console.BackgroundColor = ConsoleColor.Black; } }
TextWriter GetWriter( TraceEventType eventType ) { if (eventType.HasFlag(TraceEventType.Error) || eventType.HasFlag(TraceEventType.Warning)) { return Console.Error; } else { return Console.Out; } }