* Refractored a bit.
[ngenerator.git] / Logger.cs
blob34ac7987803cfd83697ccacdf44e065484d10fc0
1 // /home/jeremie/TaoParser/NGenerator/Logger.cs
2 // Writtent by jeremie at 17:47 09/06/2007
3 //
4 // This file is licensed under the LGPL licence as described in the COPYING file
6 using System;
7 using System.IO;
8 using System.Diagnostics;
10 namespace NGenerator
12 public enum LogType {
13 Debug,
14 Error
17 public static class Logger
19 static TextWriter sw = Console.Out;
21 public static TextWriter Output {
22 get {
23 return sw;
25 set {
26 if (value == null)
27 throw new ArgumentNullException("value");
28 sw.Dispose();
29 sw = value;
33 private static void Log(LogType type, string mess)
35 StackTrace st = new StackTrace();
36 StackFrame sf = st.GetFrame(2);
38 if (mess == null || sf == null)
39 return;
41 if (sw == Console.Out)
42 Console.ForegroundColor = (type == LogType.Error) ? ConsoleColor.DarkRed : ConsoleColor.DarkBlue;
44 sw.WriteLine(type.ToString()+" -> "+ sf.GetMethod().Name+" :: "+mess);
46 if (sw == Console.Out)
47 Console.ResetColor();
50 [System.Diagnostics.ConditionalAttribute("__DEBUG__")]
51 public static void Debug(string mess)
53 Log(LogType.Debug, mess);
56 public static void Error(string mess, Exception ex)
58 string message = (ex == null) ? mess : (mess + ", Exception type : " + ex.GetType().ToString()
59 + ", Exception message : " + ex.Message);
60 Log(LogType.Error, message);