Пример #1
0
 /// <summary>
 /// Logs the specified warning message with an exception.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="message">The warning message.</param>
 /// <param name="exception">An exception to log with the message.</param>
 /// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
 public static void Warning([NotNull] this ILogger logger, string message, Exception exception, CallerInfo callerInfo = null)
 {
     logger.Log(new LogMessage(logger.Module, LogMessageType.Warning, message, exception, callerInfo));
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LogMessage" /> class.
 /// </summary>
 /// <param name="module">The module.</param>
 /// <param name="type">The type.</param>
 /// <param name="text">The text.</param>
 /// <param name="exception">The exception.</param>
 /// <param name="callerInfo">The caller info.</param>
 public LogMessage(string module, LogMessageType type, string text, Exception exception, CallerInfo callerInfo)
 {
     Module     = module;
     Type       = type;
     Text       = text;
     Exception  = exception;
     CallerInfo = callerInfo;
 }
Пример #3
0
 /// <summary>
 /// Logs the specified info message.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="message">The info message.</param>
 /// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
 public static void Info([NotNull] this ILogger logger, string message, CallerInfo callerInfo = null)
 {
     Info(logger, message, null, callerInfo);
 }
Пример #4
0
 /// <summary>
 /// Logs the specified warning message with an exception.
 /// </summary>
 /// <param name="message">The warning message.</param>
 /// <param name="exception">An exception to log with the message.</param>
 /// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
 public void Warning(string message, Exception exception, CallerInfo callerInfo = null)
 {
     Log(new LogMessage(Module, LogMessageType.Warning, message, exception, callerInfo));
 }
Пример #5
0
 /// <summary>
 /// Logs the specified warning message.
 /// </summary>
 /// <param name="message">The warning message.</param>
 /// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
 public void Warning(string message, CallerInfo callerInfo = null)
 {
     Warning(message, null, callerInfo);
 }
Пример #6
0
 /// <summary>
 /// Logs the specified debug message.
 /// </summary>
 /// <param name="message">The debug message.</param>
 /// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
 public void Debug(string message, CallerInfo callerInfo = null)
 {
     Debug(message, null, callerInfo);
 }
Пример #7
0
 /// <summary>
 /// Logs the specified info message.
 /// </summary>
 /// <param name="message">The info message.</param>
 /// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
 public void Info(string message, CallerInfo callerInfo = null)
 {
     Info(message, null, callerInfo);
 }
Пример #8
0
 /// <summary>
 /// Logs the specified verbose message with an exception.
 /// </summary>
 /// <param name="message">The verbose message.</param>
 /// <param name="exception">An exception to log with the message.</param>
 /// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
 public void Verbose(string message, Exception exception, CallerInfo callerInfo = null)
 {
     Log(new LogMessage(Module, LogMessageType.Verbose, message, exception, callerInfo));
 }
Пример #9
0
 /// <summary>
 /// Logs the specified verbose message.
 /// </summary>
 /// <param name="message">The verbose message.</param>
 /// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
 public void Verbose(string message, CallerInfo callerInfo = null)
 {
     Verbose(message, null, callerInfo);
 }
Пример #10
0
 /// <summary>
 /// Logs the specified fatal message.
 /// </summary>
 /// <param name="message">The fatal message.</param>
 /// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
 public void Fatal(string message, CallerInfo callerInfo = null)
 {
     Fatal(message, null, callerInfo);
 }
Пример #11
0
 /// <summary>
 /// Logs the specified fatal message with an exception.
 /// </summary>
 /// <param name="message">The fatal message.</param>
 /// <param name="exception">An exception to log with the message.</param>
 /// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
 public void Fatal(string message, Exception exception, CallerInfo callerInfo = null)
 {
     Log(new LogMessage(Module, LogMessageType.Fatal, message, exception, callerInfo));
 }
Пример #12
0
 /// <summary>
 /// Logs the specified error message.
 /// </summary>
 /// <param name="message">The error message.</param>
 /// <param name="callerInfo">Information about the caller. Default is null, otherwise use <see cref="CallerInfo.Get"/>.</param>
 public void Error(string message, CallerInfo callerInfo = null)
 {
     Error(message, null, callerInfo);
 }
Пример #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LogMessage" /> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="type">The type.</param>
        /// <param name="text">The text.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="callerInfo">The caller info.</param>
        public LogMessage(string module, LogMessageType type, string text, Exception exception, CallerInfo callerInfo)
        {
            if (exception != null)
            {
                try {
                    // Get stack trace for the exception with source file information
                    StackTrace st = new StackTrace(exception, true);
                    // Get the top stack frame
                    StackFrame frame = st.GetFrame(0);
                    // Get the line number from the stack frame
                    int line = frame.GetFileLineNumber();
                    if (line != 0)
                    {
                        // try to add it to the front of the text
                        text = "{line #" + line.ToString() + "} " + text;
                    }
                } catch (Exception e) { /* couldn't get line info */ }
            }

            Module     = module;
            Type       = type;
            Text       = text;
            Exception  = exception;
            CallerInfo = callerInfo;
        }
Пример #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LogMessage" /> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="type">The type.</param>
        /// <param name="text">The text.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="callerInfo">The caller info.</param>
        public LogMessage(string module, LogMessageType type, string text, Exception exception, CallerInfo callerInfo)
        {
            if (exception != null)
            {
                // if file logging is enabled, write it here
                ErrorFileLogger.WriteExceptionToFile(exception, type.ToString() + ", " + text + ", " + module + ", File: " +
                                                     (callerInfo?.FilePath ?? "none") + ", Line: " + (callerInfo?.LineNumber.ToString() ?? "none"));
            }

            Module     = module;
            Type       = type;
            Text       = text;
            Exception  = exception;
            CallerInfo = callerInfo;
        }