1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86:
using System; using System.Collections.Generic; using System.Text; using log4net; public static class Log { private const string LOG_REPOSITORY = "Default"; // this should likely be set in the web config. private static ILog m_log; public static void Init() { log4net.Config.XmlConfigurator.Configure(); } public static void Write(string message, LogMessageType messageType) { DoLog(message, messageType, null, Type.GetType("System.Object")); } public static void Write(string message, LogMessageType messageType, Type type) { DoLog(message, messageType, null, type); } public static void Write(string message, LogMessageType messageType, Exception ex) { DoLog(message, messageType, ex, Type.GetType("System.Object")); } public static void Write(string message, LogMessageType messageType, Exception ex, Type type) { DoLog(message, messageType, ex, type); } public static void Assert(bool condition, string message) { Assert(condition, message, Type.GetType("System.Object")); } public static void Assert(bool condition, string message, Type type) { if (condition == false) Write(message, LogMessageType.Info); } private static void DoLog(string message, LogMessageType messageType, Exception ex, Type type) { m_log = LogManager.GetLogger(type); switch (messageType) { case LogMessageType.Debug: Log.m_log.Debug(message, ex); break; case LogMessageType.Info: Log.m_log.Info(message, ex); break; case LogMessageType.Warn: Log.m_log.Warn(message, ex); break; case LogMessageType.Error: Log.m_log.Error(message, ex); break; case LogMessageType.Fatal: Log.m_log.Fatal(message, ex); break; } } public enum LogMessageType { Debug, Info, Warn, Error, Fatal } }