* Now command like /c and /j works in any tabs (previously you had to be in the serve...
[circ.git] / Circ.Lib / Common / Logger.cs
blob4846f717f1571a80ac9fe63be2c1c0af44c5f932
1 #region License
2 /* Circ.Lib : main library behind Circ
3 * Copyright (C) 2007 LAVAL Jérémie
5 * This file is licensed under the terms of the LGPL.
7 * For the complete licence see the file COPYING.
8 */
9 #endregion
10 using System;
11 using System.IO;
12 using System.Diagnostics;
13 using System.Reflection;
15 namespace Circ
17 public enum LogType {
18 Debug,
19 Error
22 public static class Logger
24 static TextWriter sw;
26 static Logger()
28 sw = Console.Out;
31 public static TextWriter Output {
32 get {
33 return sw;
35 set {
36 if (value == null)
37 throw new ArgumentNullException("value");
38 sw.Dispose();
39 sw = value;
43 private static void Log(LogType type, string mess)
45 StackTrace st = new StackTrace();
46 StackFrame sf = st.GetFrame(2);
48 if (mess == null || sf == null)
49 return;
51 sw.WriteLine(type.ToString()+" -> "+ sf.GetMethod().Name+" :: "+mess);
54 [System.Diagnostics.ConditionalAttribute("__DEBUG__")]
55 public static void Debug(string mess)
57 Log(LogType.Debug, mess);
60 public static void Error(string mess, Exception ex)
62 string message = (ex == null) ? mess : (mess + ", Exception type : " + ex.GetType().ToString()
63 + ", Exception message : " + ex.Message);
64 Log(LogType.Error, message);