Ejemplo n.º 1
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;
            }
            }
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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());
        }