12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System.Diagnostics;
- namespace WingServerCommon.Log
- {
- /// <summary>
- /// Logger - Should register log engine before usage
- /// </summary>
- public class Logger
- {
- private static ILogEngine _logEngine = new DefaultLogEngine();
- public static bool Debug { get; set; }
- /// <summary>
- /// Register a log engine
- /// </summary>
- /// <param name="logEngine"></param>
- public static void RegisterEngine(ILogEngine logEngine)
- {
- _logEngine = logEngine;
- }
- /// <summary>
- /// Write log with info level
- /// </summary>
- /// <param name="msg"></param>
- public static void WriteLineInfo(string msg)
- {
- _logEngine.Write(TraceLevel.Info, msg);
- }
- /// <summary>
- /// Write log with warning level
- /// </summary>
- /// <param name="msg"></param>
- public static void WriteLineWarn(string msg)
- {
- _logEngine.Write(TraceLevel.Warning, msg);
- }
- /// <summary>
- /// Write log with error level
- /// </summary>
- /// <param name="msg"></param>
- public static void WriteLineError(string msg)
- {
- _logEngine.Write(TraceLevel.Error, msg);
- }
-
- /// <summary>
- /// Write log with verbose level. In most cases we write verbose log in debug mode
- /// </summary>
- /// <param name="msg"></param>
- public static void WriteLineVerbose(string msg)
- {
- _logEngine.Write(TraceLevel.Verbose, msg);
- }
- /// <summary>
- /// Write debug log
- /// </summary>
- /// <param name="msg"></param>
- public static void WriteLineDebug(string msg)
- {
- if(Debug)
- {
- _logEngine.Write(TraceLevel.Off, msg);
- }
- }
- class DefaultLogEngine : ILogEngine
- {
- public void Write(TraceLevel level, string msg){
- System.Console.WriteLine("Should register customer log engine first.");
- }
- }
- }
- }
|