コード例 #1
0
        /// <summary>
        /// 职责链模式
        /// </summary>
        static void ChainOfResponsibility()
        {
            Console.WriteLine($"职责链模式{Environment.NewLine}-------------------------------------------");

            ILoggerHandler infoLogger  = new InfoLogger();
            ILoggerHandler debugLogger = new DebugLogger();
            ILoggerHandler warnLogger  = new WarnLogger();
            ILoggerHandler errorLogger = new ErrorLogger();

            infoLogger.Successor  = debugLogger;
            debugLogger.Successor = errorLogger;
            //errorLogger.Successor = warnLogger;

            infoLogger.Record("AAAAAAAAAAAA", LogLevelEmun.INFO);
            infoLogger.Record("BBBBBBBBBBBB", LogLevelEmun.DEBUG);
            infoLogger.Record("CCCCCCCCCCCC", LogLevelEmun.WARN);
            infoLogger.Record("DDDDDDDDDDDD", LogLevelEmun.ERROR);

            Console.ReadKey();
        }
コード例 #2
0
ファイル: CommonLogger.cs プロジェクト: mqd520/Md5PwdTool
        /// <summary>
        /// Write Log
        /// </summary>
        /// <param name="category">category</param>
        /// <param name="log">log</param>
        /// <param name="e">exception</param>
        public static void WriteLog(ELogCategory category, object log = null, Exception e = null)
        {
            switch (category)
            {
            case ELogCategory.Debug:
                if (debugLogger.IsDebugEnabled)
                {
                    if (log != null)
                    {
                        if (e != null)
                        {
                            debugLogger.Debug(log, e);
                        }
                        else
                        {
                            debugLogger.Debug(log);
                        }
                    }
                    else
                    {
                        if (e != null)
                        {
                            debugLogger.Debug(e);
                        }
                    }
                }
                break;

            case ELogCategory.Info:
                if (infoLogger.IsInfoEnabled)
                {
                    if (log != null)
                    {
                        if (e != null)
                        {
                            infoLogger.Info(log, e);
                        }
                        else
                        {
                            infoLogger.Info(log);
                        }
                    }
                    else
                    {
                        if (e != null)
                        {
                            infoLogger.Info(e);
                        }
                    }
                }
                break;

            case ELogCategory.Warn:
                if (WarnLogger.IsWarnEnabled)
                {
                    if (log != null)
                    {
                        if (e != null)
                        {
                            WarnLogger.Warn(log, e);
                        }
                        else
                        {
                            WarnLogger.Warn(log);
                        }
                    }
                    else
                    {
                        if (e != null)
                        {
                            WarnLogger.Warn(e);
                        }
                    }
                }
                break;

            case ELogCategory.Error:
                if (errorLogger.IsErrorEnabled)
                {
                    if (log != null)
                    {
                        if (e != null)
                        {
                            errorLogger.Error(log, e);
                        }
                        else
                        {
                            errorLogger.Error(log);
                        }
                    }
                    else
                    {
                        if (e != null)
                        {
                            errorLogger.Error(e);
                        }
                    }
                }
                break;

            case ELogCategory.Fatal:
                if (fatalLogger.IsFatalEnabled)
                {
                    if (log != null)
                    {
                        if (e != null)
                        {
                            fatalLogger.Fatal(log, e);
                        }
                        else
                        {
                            fatalLogger.Fatal(log);
                        }
                    }
                    else
                    {
                        if (e != null)
                        {
                            fatalLogger.Fatal(e);
                        }
                    }
                }
                break;

            case ELogCategory.Sql:
                if (sqlLogger.IsInfoEnabled)
                {
                    if (log != null)
                    {
                        if (e != null)
                        {
                            sqlLogger.Info(log, e);
                        }
                        else
                        {
                            sqlLogger.Info(log);
                        }
                    }
                    else
                    {
                        if (e != null)
                        {
                            sqlLogger.Info(e);
                        }
                    }
                }
                break;

            case ELogCategory.Security:
                if (securityLogger.IsInfoEnabled)
                {
                    if (log != null)
                    {
                        if (e != null)
                        {
                            securityLogger.Info(log, e);
                        }
                        else
                        {
                            securityLogger.Info(log);
                        }
                    }
                    else
                    {
                        if (e != null)
                        {
                            securityLogger.Info(e);
                        }
                    }
                }
                break;
            }
        }
コード例 #3
0
 /// <remarks/>
 public void WarnMessageAsync(WarnLogger log, object userState) {
     if ((this.WarnMessageOperationCompleted == null)) {
         this.WarnMessageOperationCompleted = new System.Threading.SendOrPostCallback(this.OnWarnMessageOperationCompleted);
     }
     this.InvokeAsync("WarnMessage", new object[] {
                 log}, this.WarnMessageOperationCompleted, userState);
 }
コード例 #4
0
 /// <remarks/>
 public void WarnMessageAsync(WarnLogger log) {
     this.WarnMessageAsync(log, null);
 }
コード例 #5
0
 public void WarnMessage(WarnLogger log) {
     this.Invoke("WarnMessage", new object[] {
                 log});
 }
コード例 #6
0
 public static void Warn(string message)
 {
     WarnLogger.Warn(message);
 }