예제 #1
0
파일: Logger.cs 프로젝트: prakashdgl/PMS
 public Logger(LoggerEnum loggerEnum)
 {
     //Factory Design Pattern
     if (loggerEnum == LoggerEnum.DataBase)
     {
         logger = new DbLogger();
     }
     else if (loggerEnum == LoggerEnum.File)
     {
         logger = new FileLogger();
     }
     else
     {
         logger = new  EmailLogger();
     }
 }
예제 #2
0
            public void logMessage(string s, LoggerEnum severity)
            {

                try
                {
                    if (instance.Log == null)
                        instance.Log = new List<Util.Log.Log>();

                    instance.Log.Add(new Log.Log() { LogMessage = s, LogType = severity });


                }
                catch (Exception ex)
                {
                    //Console.WriteLine(ex.Message, new object[0]);
                }
            }
예제 #3
0
 public void WriteToLog(Object message, Type type, LoggerEnum logger)
 {
     switch (logger)
     {
         case LoggerEnum.Info:
             LogManager.GetLogger(type).Info(message);
             break;
         case LoggerEnum.Debug:
             LogManager.GetLogger(type).Debug(message);
             break;
         case LoggerEnum.Error:
             LogManager.GetLogger(type).Error(message);
             break;
         default:
             break;
     }
 }
예제 #4
0
        private log4net.ILog SettingProperties(Log4NetMessageModel message,LoggerEnum loggerEnum)
        {
            if (!string.IsNullOrEmpty(this.module)) {
                message.module = this.module;
            }
            if (!string.IsNullOrEmpty(this.systemName)) {
                message.systemName = this.systemName;
            }

            log4net.ILog log = null;
            log = string.IsNullOrEmpty(message.module) ? log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType) : log4net.LogManager.GetLogger(loggerEnum.ToString() + message.module);
            double executionTime = 0;
            if (message.executionTime == null) {
                if (message.startTime != null && message.endTime != null) {
                    executionTime = message.endTime.Value.Subtract(message.startTime.Value).TotalMilliseconds;
                }
            }
            if (string.IsNullOrEmpty(message.url)) {
                message.url =HttpContext.Current!=null? HttpContext.Current.Request.Url.AbsolutePath:string.Empty;
            }
            if (string.IsNullOrEmpty(message.parameters)) {
                message.parameters = HttpContext.Current != null ? HttpContext.Current.Request.Params.ToString() : string.Empty;
            }
            if (string.IsNullOrEmpty(message.serverIP)) {
                message.serverIP = HttpContext.Current != null ? HttpContext.Current.Request.UserHostAddress : string.Empty;
            }
            if (string.IsNullOrEmpty(message.clientIP) && HttpContext.Current!=null) {
                message.clientIP = GetClientIP();
            }
            log4net.ThreadContext.Properties["module"] = message.module;
            log4net.ThreadContext.Properties["executionTime"] = executionTime;
            log4net.ThreadContext.Properties["systemName"] = message.systemName;
            log4net.ThreadContext.Properties["serverIP"] = message.serverIP;
            log4net.ThreadContext.Properties["clientIP"] = message.clientIP;
            log4net.ThreadContext.Properties["parameters"] = message.parameters;
            log4net.ThreadContext.Properties["url"] = message.url;
            return log;
        }
예제 #5
0
        public void Add(string text, LoggerEnum loggerEnum = LoggerEnum.Info)
        {
            if (RichTextBox == null)
            {
                return;
            }

            if (!RichTextBox.InvokeRequired)
            {
                string log   = String.Empty;
                Color  color = Color.Black;
                switch (loggerEnum)
                {
                case LoggerEnum.Alert:
                    color = alertColor;
                    break;

                case LoggerEnum.Debug:
                    color = debugColor;
                    break;

                case LoggerEnum.Error:
                    color = errorColor;
                    break;

                case LoggerEnum.Info:
                    color = infoColor;
                    break;
                }

                string time = DateTime.Now.ToShortTimeString();
                RichTextBox.AppendText($"{time} - " + text, color, true);
            }
            else
            {
                RichTextBox.Invoke(new Action(() => Add(text, loggerEnum)));
            }
        }
예제 #6
0
            public void logMessage(string s, LoggerEnum severity)
            {

                try
                {
                    Console.WriteLine(s);
                    if (_Output == null)
                    {
                        _Output = new System.IO.StreamWriter(_logFile, true, System.Text.UnicodeEncoding.Default);
                    }

                    _Output.WriteLine(System.DateTime.Now + "\t" + severity.ToString() + "\t" + s + Environment.NewLine, new object[0]);

                    if (_Output != null)
                    {
                        _Output.Close();
                        _Output = null;
                    }

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message, new object[0]);
                }
            }
예제 #7
0
 public LoggerMediumAttribute(LoggerEnum loggerMedium)
 {
     this.LoggerMedium = loggerMedium.ToString();
 }
예제 #8
0
        public static ILog Create(LoggerEnum logger) {

            return IocFactory.ResolveByName<ILog>(logger.ToString());

        }