/[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

revision 414 by william, Fri Jun 22 08:21:18 2012 UTC revision 415 by william, Fri Jun 22 08:33:51 2012 UTC
# Line 1  Line 1 
1  #region Logging Defines  #region Logging Defines
2  // include this any class or method that required logging, and comment-out what is not needed  // include this any class or method that required logging, and comment-out what is not needed
3  #define LOGGING_ENABLED  #define LOGGING_ENABLED // this is only valid within the logger class
4  #region Enabled logging levels  #region Enabled logging levels
5  #define LOGGING_ENABLE_INFO  #define LOGGING_ENABLE_INFO
6  #define LOGGING_ENABLE_WARN  #define LOGGING_ENABLE_WARN
# Line 24  using System.Diagnostics; Line 24  using System.Diagnostics;
24    
25  namespace RomCheater.Logging  namespace RomCheater.Logging
26  {  {
27      public interface ILogger      //public interface ILogger
28      {      //{
29          void Write(string format, params object[] args);      //    void Write(string format, params object[] args);
30          void WriteLine(string format, params object[] args);      //    void WriteLine(string format, params object[] args);
31      }      //}
32    
33    
34      #region loggerflags      #region loggerflags
# Line 210  namespace RomCheater.Logging Line 210  namespace RomCheater.Logging
210          public static class Info          public static class Info
211          {          {
212              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(INFO) " + format; }              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(INFO) " + format; }
213              [Conditional("LOGGING_ENABLE_INFO"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_INFO")]
214              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.INFO)) { xlogger.Write(CreateNewFormat(format), args); } }              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.INFO)) { xlogger.Write(CreateNewFormat(format), args); } }
215              [Conditional("LOGGING_ENABLE_INFO"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_INFO")]
216              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.INFO)) { xlogger.WriteLine(CreateNewFormat(format), args); } }              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.INFO)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
217          }          }
218          public static class Warn          public static class Warn
219          {          {
220              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(WARN) " + format; }              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(WARN) " + format; }
221              [Conditional("LOGGING_ENABLE_WARN"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_WARN")]
222              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.WARN)) { xlogger.Write(CreateNewFormat(format), args); } }              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.WARN)) { xlogger.Write(CreateNewFormat(format), args); } }
223              [Conditional("LOGGING_ENABLE_WARN"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_WARN")]
224              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.WARN)) { xlogger.WriteLine(CreateNewFormat(format), args); } }              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.WARN)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
225          }          }
226          public static class Debug          public static class Debug
227          {          {
228              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(DEBUG) " + format; }              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(DEBUG) " + format; }
229              [Conditional("LOGGING_ENABLE_DEBUG"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_DEBUG")]
230              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.DEBUG)) { xlogger.Write(CreateNewFormat(format), args); } }              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.DEBUG)) { xlogger.Write(CreateNewFormat(format), args); } }
231              [Conditional("LOGGING_ENABLE_DEBUG"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_DEBUG")]
232              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.DEBUG)) { xlogger.WriteLine(CreateNewFormat(format), args); } }              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.DEBUG)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
233          }          }
234          public static class VerboseDebug          public static class VerboseDebug
235          {          {
236              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(VERBOSE DEBUG) " + format; }              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(VERBOSE DEBUG) " + format; }
237              [Conditional("LOGGING_ENABLE_VERBOSEDEBUG"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_VERBOSEDEBUG")]
238              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.VERBOSE_DEBUG)) { xlogger.Write(CreateNewFormat(format), args); } }              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.VERBOSE_DEBUG)) { xlogger.Write(CreateNewFormat(format), args); } }
239              [Conditional("LOGGING_ENABLE_VERBOSEDEBUG"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_VERBOSEDEBUG")]
240    
241              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.VERBOSE_DEBUG)) { xlogger.WriteLine(CreateNewFormat(format), args); } }              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.VERBOSE_DEBUG)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
242          }          }
243          public static class Error          public static class Error
244          {          {
245              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(ERROR) " + format; }              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(ERROR) " + format; }
246              [Conditional("LOGGING_ENABLE_ERROR"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_ERROR")]
247              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.ERROR)) { xlogger.Write(CreateNewFormat(format), args); } }              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.ERROR)) { xlogger.Write(CreateNewFormat(format), args); } }
248              [Conditional("LOGGING_ENABLE_ERROR"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_ERROR")]
249              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.ERROR)) { xlogger.WriteLine(CreateNewFormat(format), args); } }              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.ERROR)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
250          }          }
251          public static class VerboseError          public static class VerboseError
252          {          {
253              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(VERBOSE ERROR) " + format; }              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(VERBOSE ERROR) " + format; }
254              [Conditional("LOGGING_ENABLE_VERBOSEERROR"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_VERBOSEERROR")]
255              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.VERBOSE_ERROR)) { xlogger.Write(CreateNewFormat(format), args); } }              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.VERBOSE_ERROR)) { xlogger.Write(CreateNewFormat(format), args); } }
256              [Conditional("LOGGING_ENABLE_VERBOSEERROR"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_VERBOSEERROR")]
257              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.VERBOSE_ERROR)) { xlogger.WriteLine(CreateNewFormat(format), args); } }              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.VERBOSE_ERROR)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
258          }          }
259          public static class Profiler          public static class Profiler
260          {          {
261              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(PROFILER) " + format; }              private static string CreateNewFormat(string format) { return "    " + CreateTimeStamp() + "(PROFILER) " + format; }
262              [Conditional("LOGGING_ENABLE_PROFILER"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_PROFILER")]
263              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.PROFILER)) { xlogger.Write(CreateNewFormat(format), args); } }              public static void Write(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.PROFILER)) { xlogger.Write(CreateNewFormat(format), args); } }
264              [Conditional("LOGGING_ENABLE_PROFILER"), Conditional("LOGGING_ENABLED")]              [Conditional("LOGGING_ENABLE_PROFILER")]
265              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.PROFILER)) { xlogger.WriteLine(CreateNewFormat(format), args); } }              public static void WriteLine(string format, params object[] args) { if (logging_flags.HasFlag(loggerflags.PROFILER)) { xlogger.WriteLine(CreateNewFormat(format), args); } }
266          }          }
267          #region Force logging          #region Force logging
# Line 310  namespace RomCheater.Logging Line 311  namespace RomCheater.Logging
311          static xlogger() { lh = new logwriter(); }          static xlogger() { lh = new logwriter(); }
312    
313          #region ILogger Members          #region ILogger Members
314            [Conditional("LOGGING_ENABLED")]
315          public static void Write(string format, params object[] args)          public static void Write(string format, params object[] args)
316          {          {
317              init();              init();
318              lh.Write(format, args);              lh.Write(format, args);
319          }          }
320            [Conditional("LOGGING_ENABLED")]
321          public static void WriteLine(string format, params object[] args)          public static void WriteLine(string format, params object[] args)
322          {          {
323              init();              init();
# Line 358  namespace RomCheater.Logging Line 361  namespace RomCheater.Logging
361      #endregion      #endregion
362    
363      #region internal class LogHelper : ILogger      #region internal class LogHelper : ILogger
364      internal class logwriter : ILogger      internal class logwriter //: ILogger
365      {      {
366          private LogWriter writer;          private LogWriter writer;
367          public logwriter() : this(null) { }          public logwriter() : this(null) { }
# Line 367  namespace RomCheater.Logging Line 370  namespace RomCheater.Logging
370              this.writer = writer;              this.writer = writer;
371          }          }
372          #region ILogger Members          #region ILogger Members
373             [Conditional("LOGGING_ENABLED")]
374          public void Write(string format, params object[] args)          public void Write(string format, params object[] args)
375          {          {
376              WriteToLog(format, false, args);              WriteToLog(format, false, args);
377          }          }
378             [Conditional("LOGGING_ENABLED")]
379          public void WriteLine(string format, params object[] args)          public void WriteLine(string format, params object[] args)
380          {          {
381              WriteToLog(format, true, args);              WriteToLog(format, true, args);

Legend:
Removed from v.414  
changed lines
  Added in v.415

  ViewVC Help
Powered by ViewVC 1.1.22