예제 #1
0
        /// <summary>
        /// Formats the message.
        /// </summary>
        /// <param name="logLevel">The log level.</param>
        /// <param name="logLocation">The log location.</param>
        /// <param name="context">The context.</param>
        /// <param name="message">The message.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public static string FormatMessage(LogLevel logLevel, LogLocation logLocation, string context, string message, Exception exception, params object[] parameters)
        {
            var lineMessage = new StringBuilder();

            if (logLocation != null)
            {
                lineMessage.AppendFormat("{0}({1},{2}): ", logLocation.File, logLocation.Line, logLocation.Column);
            }

            // Write log parsable by Visual Studio
            var levelName = Enum.GetName(typeof(LogLevel), logLevel).ToLower();

            lineMessage.AppendFormat("{0}:{1}{2}", levelName, (context != null) ? $" in {context} " : "", message != null ? string.Format(message, parameters) : "");

            return(lineMessage.ToString());
        }
        /// <summary>
        /// Logs the specified log message.
        /// </summary>
        /// <param name="logLevel">The log level</param>
        /// <param name="logLocation">The log location.</param>
        /// <param name="code">The code.</param>
        /// <param name="context">The context.</param>
        /// <param name="message">The message.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="parameters">The parameters.</param>
        public override void Log(LogLevel logLevel, LogLocation logLocation, string context, string code, string message, Exception exception, params object[] parameters)
        {
            lock (this)
            {
                if (Output == null)
                {
                    return;
                }

                string lineMessage = FormatMessage(logLevel, logLocation, context, message, exception, parameters);

                Output.WriteLine(lineMessage);
                Output.Flush();

                if (exception != null)
                {
                    Output.WriteLine(exception.ToString());
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Logs the specified log message.
 /// </summary>
 /// <param name="logLevel">The log level</param>
 /// <param name="logLocation">The log location.</param>
 /// <param name="context">The context.</param>
 /// <param name="message">The message.</param>
 /// <param name="exception">The exception.</param>
 /// <param name="parameters">The parameters.</param>
 public abstract void Log(LogLevel logLevel, LogLocation logLocation, string context, string code, string message, Exception exception, params object[] parameters);