Exemplo n.º 1
0
 public static void Log(Enums.LogType type, string text)
 {
     if (MsgText != null)
     {
         MsgText(type, text);
     }
 }
Exemplo n.º 2
0
        public void LogEntry(Enums.LogType logType, string message, Exception exception)
        {
            switch (logType)
            {
            case Enums.LogType.Error:
                if (exception == null)
                {
                    LogError(message);
                }
                else
                {
                    LogError(exception);
                }
                break;

            case Enums.LogType.Warning:
                LogWarning(message);
                break;

            case Enums.LogType.Information:
                LogInfo(message);
                break;

            default:
                LogInfo(message);
                break;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Logs a given message.
 /// </summary>
 /// <param name="message">Message to be logged.</param>
 /// <param name="logType">LogType to be used.</param>
 public void Log(string message, Enums.LogType logType)
 {
     prepareFile();
     using (StreamWriter sw = File.AppendText(_fullPath))
     {
         sw.WriteLine(
             createLogEntry(message, logType));
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Logs a given exception.
 /// </summary>
 /// <param name="ex">Exception to be logged.</param>
 /// <param name="logType">LogType to be used.</param>
 public void Log(Exception ex, Enums.LogType logType)
 {
     prepareFile();
     using (StreamWriter sw = File.AppendText(_fullPath))
     {
         sw.WriteLine(
             createLogEntry(ex, logType));
     }
 }
Exemplo n.º 5
0
        public Task LogEventAsync(string eventDescription, Enums.LogType type, params object[] args)
        {
            var loggedEvent = new LogMessage
            {
                LogDateTime = DateTime.Now.ToLocalTime(),
                Message     = string.Format("{0} - {1}", type.ToString(), string.Format(eventDescription, args)),
                LogType     = type
            };

            return(this.InsertLogMessage(loggedEvent));
        }
Exemplo n.º 6
0
        internal static void Write(Enums.LogType type, string text)
        {
            DateTime now = DateTime.Now;
            string   tmp =
                "[" + now.Hour +
                ":" + now.Minute +
                ":" + now.Second +
                "] [" + Enum.GetName(typeof(Enums.LogType), type) +
                "] " + text + "\r\n";

            main.NewLogOutput.Invoke(main, tmp);
        }
Exemplo n.º 7
0
        public static void Log(object message, Enums.LogType logType = Enums.LogType.Info)
        {
            switch (logType)
            {
            case Enums.LogType.Info:
            {
                _logger.Info(message);

                Console.WriteLine($"[{logType.ToString()}] {message}");
                break;
            }

            case Enums.LogType.Warning:
            {
                _logger.Warn(message);

                if (Configuration.Debug)
                {
                    Console.ForegroundColor = ConsoleColor.DarkMagenta;
                    Console.WriteLine($"[{logType.ToString()}] {message}");
                    Console.ResetColor();
                }
                break;
            }

            case Enums.LogType.Error:
            {
                _logger.Error(message);

                if (Configuration.Debug)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"[{logType.ToString()}] {message}");
                    Console.ResetColor();
                }
                break;
            }

            case Enums.LogType.Debug:
            {
                if (Configuration.Debug)
                {
                    _logger.Debug(message);

                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine($"[{logType.ToString()}] {message}");
                    Console.ResetColor();
                }
                break;
            }
            }
        }
Exemplo n.º 8
0
        //public void WriteLog(string text, int logType)
        //{
        //    EventLogEntryType eventLogType =
        //        logType == (int)Enums.LogType.Info ? EventLogEntryType.Information : (
        //        logType == (int)Enums.LogType.Error ? EventLogEntryType.Error :
        //        EventLogEntryType.Information);

        //    EventLog mEventLog = new EventLog("Log Manager");
        //    mEventLog.WriteEntry(text, eventLogType);
        //}

        public void WriteLog(string text, Enums.LogType logType, string source)
        {
            EventLogEntryType eventLogType =
                logType == Enums.LogType.Info? EventLogEntryType.Information : (
                    logType == Enums.LogType.Error ? EventLogEntryType.Error :
                    EventLogEntryType.Information);

            EventLog mEventLog = new EventLog("")
            {
                Source = source
            };

            mEventLog.WriteEntry(text, eventLogType);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a log entry from a string.
        /// </summary>
        /// <param name="message">Message to be logged.</param>
        /// <param name="logType">LogType to be used.</param>
        /// <returns>The log entry.</returns>
        private string createLogEntry(string message, Enums.LogType logType)
        {
            StringBuilder sbuilder = new StringBuilder();

            sbuilder.Append("[")
            .Append(DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss.fff tt"))
            .Append("]")
            .Append("[")
            .Append(logType.ToString("g"))
            .Append("]")
            .Append(" ")
            .Append(message);

            return(sbuilder.ToString());
        }
Exemplo n.º 10
0
        /// <summary>
        /// 记录系统运行日志
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="level">日志类型</param>
        /// <param name="message">日志信息</param>
        public static void Write(Type type, Enums.LogType logType, string message)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(type);
            message = string.Format("{2}{2}{0}{2}Message:{1}{2}{2}{3}{2}{2}", LogPosition(), message, Environment.NewLine, "================================================================================");

            switch (logType)
            {
            case Enums.LogType.Fatal:
                if (log.IsFatalEnabled)
                {
                    log.Fatal(message);
                }
                break;

            case Enums.LogType.Error:
                if (log.IsErrorEnabled)
                {
                    log.Error(message);
                }
                break;

            case Enums.LogType.Warn:
                if (log.IsWarnEnabled)
                {
                    log.Warn(message);
                }
                break;

            case Enums.LogType.Debug:
                if (log.IsDebugEnabled)
                {
                    log.Debug(message);
                }
                break;

            case Enums.LogType.Info:
                if (log.IsInfoEnabled)
                {
                    log.Info(message);
                }
                break;
            }

            log = null;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates a log entry from an exception.
        /// </summary>
        /// <param name="ex">Exception to be logged.</param>
        /// <param name="logType">LogType to be used.</param>
        /// <returns>The log entry.</returns>
        private string createLogEntry(Exception ex, Enums.LogType logType)
        {
            StringBuilder sbuilder = new StringBuilder();

            sbuilder.Append("[")
            .Append(DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss.fff tt"))
            .Append("]")
            .Append("[")
            .Append(logType.ToString("g"))
            .Append("]")
            .Append(" ")
            .Append(ex.GetType().ToString())
            .Append(" - ")
            .Append(ex.Message)
            .Append(" - ")
            .Append(ex.StackTrace);

            return(sbuilder.ToString());
        }
Exemplo n.º 12
0
        public void ShowMsg(Enums.LogType type, string txt)
        {
            switch (type)
            {
            case Enums.LogType.Login:
                Dispatcher.Invoke(new Action(() => listBox1.Items.Add(txt)));
                break;

            case Enums.LogType.Logout:
                Dispatcher.Invoke(new Action(() => listBox1.Items.Remove(txt)));
                break;

            default:

                Brush brush = Brushes.Black;
                if (type == Enums.LogType.Start)
                {
                    brush = Brushes.Red;
                }
                else if (type == Enums.LogType.Error)
                {
                    brush = Brushes.Blue;
                }
                Dispatcher.Invoke(new Action(() =>
                {
                    var p = new Paragraph();     // Paragraph 类似于 html 的 P 标签
                    var r = new Run(txt);        // Run 是一个 Inline 的标签
                    p.Inlines.Add(r);
                    p.Foreground = brush;        //设置字体颜色
                    // 除了设置属性,事件也可以在这里设置

                    Doc.Blocks.Add(p);
                    richTextBox1.Document = Doc;
                }));
                break;
            }
        }
Exemplo n.º 13
0
 public void LogEntry(Enums.LogType logType, string message)
 {
     LogEntry(logType, message, null);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Writes message to console output. Maintains foreground color while applying a temporary color. Locks output to ensure color is applied (may be incorrect way to go about it)
        /// </summary>
        /// <param name="message"></param>
        /// <param name="includeDate"></param>
        /// <param name="includeTime"></param>
        /// <param name="type"></param>
        public static void Log(string message, bool includeDate = false, bool includeTime = false, Enums.LogType type = Enums.LogType.Normal)
        {
            lock (Console.Out)
            {
                ConsoleColor prevColor = Console.ForegroundColor;
                switch (type)
                {
                case Enums.LogType.Normal:
                    Console.ForegroundColor = ConsoleColor.White;
                    break;

                case Enums.LogType.Success:
                    Console.ForegroundColor = ConsoleColor.Green;
                    break;

                case Enums.LogType.Failure:
                    Console.ForegroundColor = ConsoleColor.Red;
                    break;
                }
                string dateTimeStr = "";
                if (includeDate && includeTime)
                {
                    dateTimeStr = $"{DateTime.UtcNow}";
                }
                else if (includeDate)
                {
                    dateTimeStr = $"{DateTime.UtcNow.ToShortDateString()}";
                }
                else
                {
                    dateTimeStr = $"{DateTime.UtcNow.ToShortTimeString()}";
                }

                if (includeDate || includeTime)
                {
                    Console.WriteLine($"[TwitchLib - {dateTimeStr}] {message}");
                }
                else
                {
                    Console.WriteLine($"[TwitchLib] {message}");
                }
                Console.ForegroundColor = prevColor;
            }
        }
Exemplo n.º 15
0
 private void Fl_NewLog(string message, Enums.LogType type)
 {
     JournalText += $"{DateTime.Now} [{Enum.GetName(typeof(Enums.LogType), type)}] - {message}\r\n";
 }
        private Task HandleExceptionAsync(HttpContext context, Exception exception)
        {
            context.Response.ContentType = "application/json";
            context.Response.StatusCode  = (int)HttpStatusCode.Forbidden;

            var message = string.Empty;

            Enums.LogType logType = Enums.LogType.Error;
            if (exception is FoundSameObjectException)
            {
                logType = Enums.LogType.SameObject;
                message = ResponseMessage.SAME_OBJECT.ToString();
            }
            else if (exception is NotFoundException)
            {
                logType = Enums.LogType.NotFound;
                message = ResponseMessage.NOT_FOUND.ToString();
            }
            else if (exception is ExistDependencyException)
            {
                logType = Enums.LogType.Error;
                message = ResponseMessage.EXIST_DEPENDENCY_OBJECTS.ToString();
            }
            else if (exception is NotFoundDependencyObjectException)
            {
                logType = Enums.LogType.NotFound;
                message = ResponseMessage.NOT_FOUND_DEPENDENCY_OBJECT.ToString();
            }
            else if (exception is RoleManagerException)
            {
                logType = Enums.LogType.Error;
                message = ResponseMessage.ERROR.ToString();
            }
            else if (exception is UserManagerException)
            {
                logType = Enums.LogType.Error;
                message = ResponseMessage.ERROR.ToString();
            }
            else if (exception is UnavailableOperationException)
            {
                logType = Enums.LogType.NoAccess;
                message = ResponseMessage.NO_ACCESS.ToString();
            }
            else if (exception is AppUnauthorizedAccessException)
            {
                logType = Enums.LogType.Error;
                context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;

                var ex = exception as AppUnauthorizedAccessException;

                if (ex.UnautorizedType == UnautorizedType.NOT_FOUND)
                {
                    if (ex.ObjectType == ObjectType.USER)
                    {
                        message = ResponseMessage.NOT_FOUND_USER.ToString();
                    }
                    else if (ex.ObjectType == ObjectType.ROLE)
                    {
                        message = ResponseMessage.NOT_FOUND_ROLE.ToString();
                    }
                }
                else if (ex.UnautorizedType == UnautorizedType.SAME_OBJECT)
                {
                    if (ex.ObjectType == ObjectType.USER)
                    {
                        message = ResponseMessage.SAME_USER.ToString();
                    }
                    else if (ex.ObjectType == ObjectType.ROLE)
                    {
                        message = ResponseMessage.SAME_ROLE.ToString();
                    }
                }
            }
            else
            {
                logType = Enums.LogType.Error;
                context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            }

            _logService.Add(logType, exception.Message);
            return(context.Response.WriteAsync(message));
        }
Exemplo n.º 17
0
 public void WriteLog(string text, Enums.LogType logType, string source)
 {
     throw new NotImplementedException();
     //TrafficTools.WriteLog.WL("Source : "+ source + ", Type : " + logType.ToString()+ ", Message : " + text);
 }
Exemplo n.º 18
0
 public void WriteLog(string text, Enums.LogType logType, string source)
 {
     throw new NotImplementedException();
 }