/[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	2013/06/17 03:32:25	667
+++ trunk/RomCheater.Logging/logger.cs	2013/06/17 04:49:09	668
@@ -195,6 +195,49 @@
     #region public static class logger
     public static class logger
     {
+        private static string GetLoggingClass()
+        {
+            const int methodindex = 4; // get this method from stacktrace
+            string c = string.Empty;
+            StackTrace stackTrace = new StackTrace();            
+            var frames = stackTrace.GetFrames().ToList();
+            List<MethodBase> methods = new List<MethodBase>();
+            frames.ForEach(s => methods.Add(s.GetMethod()));
+            
+            var method = methods[methodindex];
+            if (method.DeclaringType != null)
+            {
+                c = method.DeclaringType.Name;
+
+                bool GetNextMethod = true;
+                if (method.DeclaringType.FullName.ToLower().StartsWith("system") || method.DeclaringType.FullName.ToLower().StartsWith("microsoft"))
+                {
+                    int NextMethodCount = methodindex;
+                    while (GetNextMethod)
+                    {
+                        if (NextMethodCount == -1)
+                        {
+                            throw new InvalidOperationException("Unable to find calling class");
+                        }
+                        method = methods[NextMethodCount--]; // walk backup the stack
+                        if (method.DeclaringType != null)
+                        {
+                            c = method.DeclaringType.Name;
+                            if (method.DeclaringType.FullName.ToLower().StartsWith("system") || method.DeclaringType.FullName.ToLower().StartsWith("microsoft"))
+                            {
+                                GetNextMethod = true;
+                            }
+                            else
+                            {
+                                GetNextMethod = false;
+                            }
+                        }
+                    }
+                }
+
+            }
+            return string.Format("({0})",c);
+        }
         private static loggerflags logging_flags;
         static logger() { SetLoggingFlags(loggerflags.DEFAULT); }
         public static void SetLoggingFlags(loggerflags flags) { logging_flags = flags; }
@@ -205,11 +248,11 @@
             string timestamp = "";
             DateTime now = DateTime.Now;
             timestamp = now.ToString("yyyy/MM/dd HH:mm:ss tt: ");
-            return timestamp;
+            return string.Format("{0}", timestamp);
         }
         public static class Info
         {
-            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(INFO) " + format; }
+            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(INFO) " + GetLoggingClass() + " " + format; }
             [Conditional("LOGGING_ENABLE_INFO")]
             public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.INFO)) { xlogger.Write(CreateNewFormat(format), args); } }
             [Conditional("LOGGING_ENABLE_INFO")]
@@ -217,7 +260,7 @@
         }
         public static class Warn
         {
-            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(WARN) " + format; }
+            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(WARN) " + GetLoggingClass() + " " + format; }
             [Conditional("LOGGING_ENABLE_WARN")]
             public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.WARN)) { xlogger.Write(CreateNewFormat(format), args); } }
             [Conditional("LOGGING_ENABLE_WARN")]
@@ -225,7 +268,7 @@
         }
         public static class Debug
         {
-            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(DEBUG) " + format; }
+            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(DEBUG) " + GetLoggingClass() + " " + format; }
             [Conditional("LOGGING_ENABLE_DEBUG")]
             public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.DEBUG)) { xlogger.Write(CreateNewFormat(format), args); } }
             [Conditional("LOGGING_ENABLE_DEBUG")]
@@ -233,7 +276,7 @@
         }
         public static class VerboseDebug
         {
-            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(VERBOSE DEBUG) " + format; }
+            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(VERBOSE DEBUG) " + GetLoggingClass() + " " + format; }
             [Conditional("LOGGING_ENABLE_VERBOSEDEBUG")]
             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")]
@@ -242,7 +285,7 @@
         }
         public static class Error
         {
-            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(ERROR) " + format; }
+            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(ERROR) " + GetLoggingClass() + " " + format; }
             [Conditional("LOGGING_ENABLE_ERROR")]
             public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.ERROR)) { xlogger.Write(CreateNewFormat(format), args); } }
             [Conditional("LOGGING_ENABLE_ERROR")]
@@ -250,7 +293,7 @@
         }
         public static class VerboseError
         {
-            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(VERBOSE ERROR) " + format; }
+            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(VERBOSE ERROR) " + GetLoggingClass() + " " + format; }
             [Conditional("LOGGING_ENABLE_VERBOSEERROR")]
             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")]
@@ -258,7 +301,7 @@
         }
         public static class Profiler
         {
-            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(PROFILER) " + format; }
+            private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(PROFILER) " + GetLoggingClass() + " " + format; }
             [Conditional("LOGGING_ENABLE_PROFILER")]
             public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.PROFILER)) { xlogger.Write(CreateNewFormat(format), args); } }
             [Conditional("LOGGING_ENABLE_PROFILER")]
@@ -269,31 +312,31 @@
         {
             public static class Info
             {
-                private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(FORCED INFO) " + format; }
+                private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(FORCED INFO) " + GetLoggingClass() + " " + format; }
                 public static void Write(string format, params object[] args) { xlogger.Write(CreateNewFormat(format), args); }
                 public static void WriteLine(string format, params object[] args) { xlogger.WriteLine(CreateNewFormat(format), args); }
             }
             public static class Warn
             {
-                private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(FORCED Warn) " + format; }
+                private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(FORCED Warn) " + GetLoggingClass() + " " + format; }
                 public static void Write(string format, params object[] args) { xlogger.Write(CreateNewFormat(format), args); }
                 public static void WriteLine(string format, params object[] args) { xlogger.WriteLine(CreateNewFormat(format), args); }
             }
             public static class Debug
             {
-                private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(FORCED DEBUG) " + format; }
+                private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(FORCED DEBUG) " + GetLoggingClass() + " " + format; }
                 public static void Write(string format, params object[] args) { xlogger.Write(CreateNewFormat(format), args); }
                 public static void WriteLine(string format, params object[] args) { xlogger.WriteLine(CreateNewFormat(format), args); }
             }
             public static class Error
             {
-                private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(FORCED ERROR) " + format; }
+                private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(FORCED ERROR) " + GetLoggingClass() + " " + format; }
                 public static void Write(string format, params object[] args) { xlogger.Write(CreateNewFormat(format), args); }
                 public static void WriteLine(string format, params object[] args) { xlogger.WriteLine(CreateNewFormat(format), args); }
             }
             public static class Profiler
             {
-                private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(FORCED PROFILER) " + format; }
+                private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(FORCED PROFILER) " + GetLoggingClass() + " " + format; }
                 public static void Write(string format, params object[] args) { xlogger.Write(CreateNewFormat(format), args); }
                 public static void WriteLine(string format, params object[] args) { xlogger.WriteLine(CreateNewFormat(format), args); }
             }

 

  ViewVC Help
Powered by ViewVC 1.1.22