/[RomCheater]/trunk/RomCheater.Logging/logger.cs
ViewVC logotype

Diff of /trunk/RomCheater.Logging/logger.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.Logging/logger.cs	2012/06/21 21:35:08	413
+++ trunk/RomCheater.Logging/logger.cs	2012/06/22 08:21:18	414
@@ -1,10 +1,26 @@
-´╗┐using System;
+´╗┐#region Logging Defines
+// include this any class or method that required logging, and comment-out what is not needed
+#define LOGGING_ENABLED
+#region Enabled logging levels
+#define LOGGING_ENABLE_INFO
+#define LOGGING_ENABLE_WARN
+#define LOGGING_ENABLE_DEBUG
+#define LOGGING_ENABLE_VERBOSEDEBUG
+#define LOGGING_ENABLE_ERROR
+#define LOGGING_ENABLE_VERBOSEERROR
+#define LOGGING_ENABLE_PROFILER
+#endregion
+#endregion
+
+
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Reflection;
 using System.Windows.Forms;
 using System.IO;
+using System.Diagnostics;
 
 namespace RomCheater.Logging
 {
@@ -16,27 +32,27 @@
 
 
     #region loggerflags
-    public class loggerflagsbase<TValue> 
+    public class loggerflagsbase<TValue>
         where TValue : IConvertible
     {
-         static loggerflagsbase()
+        static loggerflagsbase()
         {
             value_pairs = new Dictionary<TValue, EnumNameValuePair<TValue>>();
             name_pairs = new Dictionary<string, EnumNameValuePair<TValue>>();
-            
+
             init_dicts();
         }
-        protected loggerflagsbase() 
+        protected loggerflagsbase()
         {
             CurrentValue = NONE;
         }
         //protected loggerflags(ushort t) : this() { CurrentValue = new EnumNameValuePair< ushort>("", t); }
-        protected loggerflagsbase(EnumNameValuePair< TValue> t) { CurrentValue = t; }
+        protected loggerflagsbase(EnumNameValuePair<TValue> t) { CurrentValue = t; }
         protected loggerflagsbase(loggerflagsbase<TValue> t) { this.CurrentValue = t.CurrentValue; }
         private static void init_dicts()
         {
-            value_pairs = new Dictionary<TValue, EnumNameValuePair< TValue>>();
-            name_pairs = new Dictionary<string, EnumNameValuePair< TValue>>();
+            value_pairs = new Dictionary<TValue, EnumNameValuePair<TValue>>();
+            name_pairs = new Dictionary<string, EnumNameValuePair<TValue>>();
             add_dict_entry(NONE);
             add_dict_entry(INFO);
             add_dict_entry(DEBUG);
@@ -89,7 +105,7 @@
                     }
                     else
                     {
-                        builder.AppendFormat(" | {0}",pair);
+                        builder.AppendFormat(" | {0}", pair);
                     }
                     count++;
                 }
@@ -115,7 +131,7 @@
         }
         public override string ToString()
         {
-            
+
             return CurrentValue.ToString();
         }
         #endregion
@@ -162,19 +178,21 @@
     //[Flags]
     public class loggerflags : loggerflagsbase<ushort>
     {
-          protected loggerflags() :base()        {        }
-          protected loggerflags(EnumNameValuePair<ushort> t) : base(t) { }
-          protected loggerflags(loggerflagsbase<ushort> t) : base(t) { }
+        protected loggerflags() : base() { }
+        protected loggerflags(EnumNameValuePair<ushort> t) : base(t) { }
+        protected loggerflags(loggerflagsbase<ushort> t) : base(t) { }
         #region implicit operators
-          public static implicit operator loggerflags(EnumNameValuePair<ushort> t) { return new loggerflags(t); }
-          public static implicit operator EnumNameValuePair<ushort>(loggerflags t) { return new EnumNameValuePair<ushort>(t.Name,t.Value); }
-          public static implicit operator ushort(loggerflags t) { return t.Value; }
-          public static implicit operator loggerflags(ushort t) { return new loggerflags(t); }
-          public static implicit operator string(loggerflags t) { return t.Name; }
+        public static implicit operator loggerflags(EnumNameValuePair<ushort> t) { return new loggerflags(t); }
+        public static implicit operator EnumNameValuePair<ushort>(loggerflags t) { return new EnumNameValuePair<ushort>(t.Name, t.Value); }
+        public static implicit operator ushort(loggerflags t) { return t.Value; }
+        public static implicit operator loggerflags(ushort t) { return new loggerflags(t); }
+        public static implicit operator string(loggerflags t) { return t.Name; }
         #endregion
 
     }
-    
+    #endregion
+
+    #region public static class logger
     public static class logger
     {
         private static loggerflags logging_flags;
@@ -191,44 +209,58 @@
         }
         public static class Info
         {
-            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp()+ "(INFO) " + format; }
+            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(INFO) " + format; }
+            [Conditional("LOGGING_ENABLE_INFO"), Conditional("LOGGING_ENABLED")]
             public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.INFO)) { xlogger.Write(CreateNewFormat(format), args); } }
+            [Conditional("LOGGING_ENABLE_INFO"), Conditional("LOGGING_ENABLED")]
             public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.INFO)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
         }
         public static class Warn
         {
             private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(WARN) " + format; }
+            [Conditional("LOGGING_ENABLE_WARN"), Conditional("LOGGING_ENABLED")]
             public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.WARN)) { xlogger.Write(CreateNewFormat(format), args); } }
+            [Conditional("LOGGING_ENABLE_WARN"), Conditional("LOGGING_ENABLED")]
             public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.WARN)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
         }
         public static class Debug
         {
             private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(DEBUG) " + format; }
+            [Conditional("LOGGING_ENABLE_DEBUG"), Conditional("LOGGING_ENABLED")]
             public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.DEBUG)) { xlogger.Write(CreateNewFormat(format), args); } }
+            [Conditional("LOGGING_ENABLE_DEBUG"), Conditional("LOGGING_ENABLED")]
             public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.DEBUG)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
         }
         public static class VerboseDebug
         {
             private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(VERBOSE DEBUG) " + format; }
+            [Conditional("LOGGING_ENABLE_VERBOSEDEBUG"), Conditional("LOGGING_ENABLED")]
             public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.VERBOSE_DEBUG)) { xlogger.Write(CreateNewFormat(format), args); } }
+            [Conditional("LOGGING_ENABLE_VERBOSEDEBUG"), Conditional("LOGGING_ENABLED")]
             public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.VERBOSE_DEBUG)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
         }
         public static class Error
         {
             private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(ERROR) " + format; }
+            [Conditional("LOGGING_ENABLE_ERROR"), Conditional("LOGGING_ENABLED")]
             public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.ERROR)) { xlogger.Write(CreateNewFormat(format), args); } }
+            [Conditional("LOGGING_ENABLE_ERROR"), Conditional("LOGGING_ENABLED")]
             public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.ERROR)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
         }
         public static class VerboseError
         {
             private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(VERBOSE ERROR) " + format; }
+            [Conditional("LOGGING_ENABLE_VERBOSEERROR"), Conditional("LOGGING_ENABLED")]
             public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.VERBOSE_ERROR)) { xlogger.Write(CreateNewFormat(format), args); } }
+            [Conditional("LOGGING_ENABLE_VERBOSEERROR"), Conditional("LOGGING_ENABLED")]
             public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.VERBOSE_ERROR)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
         }
         public static class Profiler
         {
             private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(PROFILER) " + format; }
+            [Conditional("LOGGING_ENABLE_PROFILER"), Conditional("LOGGING_ENABLED")]
             public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.PROFILER)) { xlogger.Write(CreateNewFormat(format), args); } }
+            [Conditional("LOGGING_ENABLE_PROFILER"), Conditional("LOGGING_ENABLED")]
             public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.PROFILER)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
         }
         #region Force logging
@@ -279,7 +311,7 @@
 
         #region ILogger Members
         public static void Write(string format, params object[] args)
-        {            
+        {
             init();
             lh.Write(format, args);
         }
@@ -317,7 +349,7 @@
                                 throw;
                             }
                         }
-                    }                    
+                    }
                 }
             }
         }
@@ -337,11 +369,11 @@
         #region ILogger Members
         public void Write(string format, params object[] args)
         {
-            WriteToLog(format,false, args);
+            WriteToLog(format, false, args);
         }
         public void WriteLine(string format, params object[] args)
         {
-            WriteToLog(format,true, args);
+            WriteToLog(format, true, args);
         }
         private void WriteToLog(string format, bool newline, params object[] args)
         {
@@ -371,5 +403,5 @@
         }
         #endregion
     }
-#endregion
+    #endregion
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22