Example #1
0
 /// <summary>
 /// Write a message to the debug output.  Changed message.LogLevel to Debug
 /// </summary>
 /// <param name="message">Hydrated message to write to log store</param>
 /// <returns>Created message that was submitted to log store or null if Debug is disabled</returns>
 public LogMessage Debug(LogMessage message)
 {
     try
     {
         message.Severity = MessageLevel.Debug;
         if (IsDebugEnabled == false)
         {
             return message;
         }
         if (OnLogDebugEventHandler != null) OnLogDebugEventHandler(message);
     }
     catch (Exception ex)
     {
         Log.LastChanceLog(ex);
     }
     return message;
 }
Example #2
0
 /// <summary>
 /// Create a log message at the Debug log level
 /// </summary>
 /// <param name="messageText">Text to write to debug log.  May contain string.format({0}) arguments</param>
 /// <param name="args">Arguments to pass to messageText</param>
 /// <param name="messageNumber">Numerical index associated with this message</param>
 /// <returns>Created message that was submitted to log store or null if Debug is disabled</returns>
 public LogMessage Debug(string messageNumber, string messageText, params object[] args)
 {
     LogMessage msg = new LogMessage();
     try
     {
         if (IsDebugEnabled == false) return null;
         msg = new LogMessage(messageNumber, messageText, args);
         msg.MessageCode = messageNumber;
         msg.Severity = MessageLevel.Debug;
         return Debug(msg);
     }
     catch (Exception ex)
     {
         Log.LastChanceLog(ex);
     }
     return msg;
 }
        public void LogWrite()
        {
            if (_log == null)
            {
                _log = Log.NewLog(this.GetType());
            }
            LogMessage logMessage = new LogMessage();
            logMessage.Severity = mapper(this.Messages.MaximumSeverity);
            ActionReplyMessageItem replyMessage = this.Messages.HighestMessage;
            if (replyMessage != null)
            {
                logMessage.MessageText = replyMessage.MessageText + " (" + replyMessage.Severity.ToString() + ") ";
                if (this.Messages.Count > 1)
                {
                    logMessage.MessageText += " 1 of " + this.Messages.Count.ToString();
                }
            }

            var sortedMessageList = Messages.OrderBy((item) => ((int)item.Severity)*-1); //sort most severe first
            int msgCount = 1;
            foreach (var msg in sortedMessageList)
            {
                string prefix = "Msg" + msgCount.ToString("00");
                logMessage.ExtendedProperties.Add(prefix + "[Severity]", msg.Severity.ToString());
                if (string.IsNullOrWhiteSpace(msg.ReferenceKey) == false)
                {
                    logMessage.ExtendedProperties.Add(prefix+"[Reference]", msg.ReferenceKey.ToString());
                }
                logMessage.ExtendedProperties.Add(prefix+"[Text]", msg.MessageText.ToString());
                if (msg.Exception != null)
                {
                    logMessage.ExtendedProperties.Add(prefix+"[Exception]", msg.Exception.Expand());
                }
                msgCount++;
            }
            
            //EXTENSION serialize DataItems and Value object and add them to extendend properties

            _log.Write(logMessage);
        }
Example #4
0
        /// <summary>
        /// Create a log message at the Error log level. Message is exception.Message
        /// </summary>
        /// <param name="exception">Exception to write to Error log</param>
        /// <returns>Created message that was submitted to log store</returns>
        public LogMessage Error(Exception exception)
        {
            try
            {
                LogMessage msg = new LogMessage();

                if (IsErrorEnabled == false) return null;

                msg.RuntimeContext = new RuntimeContext(RuntimeContextOptions.HttpRequestContext | RuntimeContextOptions.MachineContext);
                msg.Severity = MessageLevel.Error;
                msg.MessageText = exception.Message;
                msg.AddException(exception);
                if (OnLogErrorEventHandler != null) OnLogErrorEventHandler(msg);
                return msg;
            }
            catch (Exception ex) //never throw an exception from log handler
            {
                Log.LastChanceLog(ex);
                return null;
            }
        }
Example #5
0
        /// <summary>
        /// Write a message to the Error output.  Changed message.LogLevel to Error
        /// </summary>
        /// <param name="message">Hydrated message to write to log store</param>
        /// <returns>Created message that was submitted to log store or null if Error is disabled</returns>
        public LogMessage Error(LogMessage message)
        {
            try
            {

                if (IsErrorEnabled == false)
                {
                    return message;
                }
                message.Severity = MessageLevel.Error;
                message.RuntimeContext = new RuntimeContext(RuntimeContextOptions.HttpRequestContext | RuntimeContextOptions.MachineContext);
                if (OnLogErrorEventHandler != null) OnLogErrorEventHandler(message);
            }
            catch (Exception ex)
            {
                Log.LastChanceLog(ex);
            }
            return message;
        }
Example #6
0
        /// <summary>
        /// Create a log message at the Warning log level. Message is exception.Message
        /// </summary>
        /// <param name="exception">Exception to write to Warning log</param>
        /// <param name="messageNumber">Numerical index associated with this message</param>
        /// <returns>Created message that was submitted to log store</returns>
        public LogMessage Warning(Exception exception, string messageNumber)
        {
            LogMessage msg = new LogMessage();
            try
            {
                if (IsWarningEnabled == false) return null;


                msg.RuntimeContext = new RuntimeContext(RuntimeContextOptions.HttpRequestContext | RuntimeContextOptions.MachineContext);
                msg.Severity = MessageLevel.Warning;
                msg.MessageText = exception.Message;
                msg.AddException(exception);
                msg.MessageCode = messageNumber;
                if (OnLogWarningEventHandler != null) OnLogWarningEventHandler(msg);
            }
            catch (Exception ex)
            {
                Log.LastChanceLog(ex);

            }
            return msg;
        }
Example #7
0
        /// <summary>
        /// Create a log message at the Warning log level
        /// </summary>
        /// <param name="messageText">Text to write to Warning log.  May contain string.format({0}) arguments</param>
        /// <param name="args">Arguments to pass to messageText</param>
        /// <returns>Created message that was submitted to log store</returns>
        public LogMessage Warning(string messageText, params object[] args)
        {
            LogMessage msg = new LogMessage();
            try
            {
                if (IsWarningEnabled == false) return null;

                msg.RuntimeContext = new RuntimeContext(RuntimeContextOptions.HttpRequestContext | RuntimeContextOptions.MachineContext);
                msg.Severity = MessageLevel.Warning;
                msg.MessageText = TextUtils.StringFormat(messageText, args);

                if (OnLogWarningEventHandler != null) OnLogWarningEventHandler(msg);
            }

            catch (Exception ex)
            {
                Log.LastChanceLog(ex);

            }
            return msg;
        }
Example #8
0
        /// <summary>
        /// Create a log message at the Debug log level. Message is exception.Message
        /// </summary>
        /// <param name="exception">Exception to write to Debug log</param>
        /// <param name="messageNumber">Numerical index associated with this message</param>
        /// <returns>Created message that was submitted to log store or null if Debug is disabled</returns>
        public LogMessage Debug(Exception exception, string messageNumber)
        {
            LogMessage msg = new LogMessage();
            try
            {
                if (IsDebugEnabled == false) return null;


                msg.Severity = MessageLevel.Debug;
                msg.MessageText = exception.Message;
                msg.AddException(exception);
                msg.MessageCode = messageNumber;
                return Debug(msg);
            }

            catch (Exception ex)
            {
                Log.LastChanceLog(ex);

            }
            return msg;
        }
 /// <summary>
 /// Format a message based on custom formatting.  Override this method to create custom formats. Default value is msg.ToString()
 /// </summary>
 /// <param name="sb">Propulated StringBuilder to add message to</param>
 /// <param name="msg">Hydrated message.  Cast this value to a custom LogMessage if using any.</param>
 protected override void FormatMessage(StringBuilder sb, LogMessage msg)
 {
     sb.Append(msg.ToString()+(new string(' ',70))+Environment.NewLine);
 }
Example #10
0
        /// <summary>
        /// Write a message to the Information output.  Changed message.LogLevel to Information
        /// </summary>
        /// <param name="message">Hydrated message to write to log store</param>
        /// <returns>Created message that was submitted to log store or null if Information is disabled</returns>
        public LogMessage Information(LogMessage message)
        {
            try
            {
                message.Severity = MessageLevel.Information;
                if (IsInformationEnabled == false)
                {
                    return message;
                }
                if (OnLogInformationEventHandler != null) OnLogInformationEventHandler(message);
            }

            catch (Exception ex)
            {
                Log.LastChanceLog(ex);

            }
            return message;
        }
Example #11
0
        /// <summary>
        /// Create a log message at the Trace log level.
        /// </summary>
        /// <param name="direction">Sets 'Enter' or 'Exit'</param>  
        /// <param name="method">Details about the method being traced</param>
        public LogMessage Trace(TraceEventType direction, MemberInfo method)
        {
            LogMessage msg = new LogMessage();
            try
            {
                if (IsTraceEnabled == false) return null;

                msg.Severity = MessageLevel.Trace;
                //msg.MessageText = TextUtils.StringFormat("{0} {1}.{2}",direction.ToString(),
                //    method.DeclaringType.FullName,method.Name);
                if (OnLogTraceEventHandler != null) OnLogTraceEventHandler(msg);
            }

            catch (Exception ex)
            {
                Log.LastChanceLog(ex);

            }
            return msg;
        }
Example #12
0
        /// <summary>
        /// Create a log message at the Trace log level. Message is exception.Message
        /// </summary>
        /// <param name="exception">Exception to write to Trace log</param>
        /// <returns>Created message that was submitted to log store</returns>
        public LogMessage Trace(Exception exception)
        {
            LogMessage msg = new LogMessage();
            try
            {
                if (IsTraceEnabled == false) return null;


                msg.Severity = MessageLevel.Trace;
                msg.MessageText = exception.Message;
                msg.AddException(exception);
                if (OnLogTraceEventHandler != null) OnLogTraceEventHandler(msg);
            }

            catch (Exception ex)
            {
                Log.LastChanceLog(ex);

            }
            return msg;

        }
Example #13
0
        /// <summary>
        /// Create a log message at the Trace log level
        /// </summary>
        /// <param name="messageText">Text to write to Trace log.  May contain string.format({0}) arguments</param>
        /// <param name="args">Arguments to pass to messageText</param>
        /// <param name="messageNumber">Numerical index associated with this message</param>
        /// <returns>Created message that was submitted to log store or null if Trace is disabled</returns>
        public LogMessage Trace(string messageNumber, string messageText, params object[] args)
        {
            LogMessage msg = new LogMessage();
            try
            {
                if (IsTraceEnabled == false) return null;

                msg.Severity = MessageLevel.Trace;
                msg.MessageText = TextUtils.StringFormat(messageText, args);
                msg.MessageCode = messageNumber;
                if (OnLogTraceEventHandler != null) OnLogTraceEventHandler(msg);
            }

            catch (Exception ex)
            {
                Log.LastChanceLog(ex);
            }
            return msg;

        }
Example #14
0
        /// <summary>
        /// Create a log message at the Debug log level.
        /// </summary>
        /// <param name="exception">Exception to write to Debug log</param>
        /// <param name="messageText">Text to write to debug log.  May contain string.format({0}) arguments</param>
        /// <returns>Created message that was submitted to log store or null if Debug is disabled</returns>
        /// <param name="args">Values to be supplied to format specifiers in messageText</param>
        public LogMessage Debug(Exception exception, string messageText, params object[] args)
        {
            LogMessage msg = new LogMessage();
            try
            {
                if (IsDebugEnabled == false) return null;

                msg.Severity = MessageLevel.Debug;
                msg.MessageText = TextUtils.StringFormat(messageText, args);
                msg.AddException(exception);
                return Debug(msg);
            }

            catch (Exception ex)
            {
                Log.LastChanceLog(ex);

            }
            return msg;
        }
Example #15
0
        /// <summary>
        /// Create a log message at the Error log level
        /// </summary>
        /// <param name="messageText">Text to write to Error log.  May contain string.format({0}) arguments</param>
        /// <param name="messageNumber">Numerical index associated with this message</param>
        /// <param name="args">Arguments to pass to messageText</param>
        /// <param name="exception">Exception that is associated with this message</param>
        public LogMessage Error(Exception exception, string messageNumber,string messageText, params object[] args)
        {
            LogMessage msg = new LogMessage();
            try
            {
                if (IsErrorEnabled == false) return null;

                msg.RuntimeContext = new RuntimeContext(RuntimeContextOptions.HttpRequestContext | RuntimeContextOptions.MachineContext);
                msg.Severity = MessageLevel.Error;
                msg.MessageText = TextUtils.StringFormat(messageText, args);
                msg.MessageCode = messageNumber;
                msg.AddException(exception);
                if (OnLogErrorEventHandler != null) OnLogErrorEventHandler(msg);
            }

            catch (Exception ex)
            {
                Log.LastChanceLog(ex);

            }
            return msg;
        }
 /// <summary>
 /// Value which is returned from here will be written to log file
 /// </summary>
 /// <param name="msg">Message that the formatter will add to the in-process string builder</param>
 /// <param name="sb">Builder that is collecting a group of messages and will be persisted once those messages are added to this builder</param>
 protected abstract void FormatMessage(StringBuilder sb, LogMessage msg);
Example #17
0
        /// <summary>
        /// Create a log message at the Information log level. Message is exception.Message
        /// </summary>
        /// <param name="exception">Exception to write to Information log</param>
        /// <param name="messageNumber">Numerical index associated with this message</param>
        /// <returns>Created message that was submitted to log store</returns>
        public LogMessage Information(Exception exception, string messageNumber)
        {
            LogMessage msg = new LogMessage();
            try
            {
                if (IsInformationEnabled == false) return null;


                msg.Severity = MessageLevel.Information;
                msg.MessageText = exception.Message;
                msg.AddException(exception);
                msg.MessageCode = messageNumber;
                if (OnLogInformationEventHandler != null) OnLogInformationEventHandler(msg);
            }

            catch (Exception ex)
            {
                Log.LastChanceLog(ex);

            }
            return msg;
        }
Example #18
0
        /// <summary>
        /// Create a log message at the Information log level.
        /// </summary>
        /// <param name="exception">Exception to write to Information log</param>
        /// <param name="messageText">Text to write to Information log.  May contain string.format({0}) arguments</param>
        /// <param name="args">Arguments to pass to messageText</param>   
        public LogMessage Information(Exception exception, string messageText, params object[] args)
        {
            LogMessage msg = new LogMessage();
            try
            {
                if (IsInformationEnabled == false) return null;

                msg.Severity = MessageLevel.Information;
                msg.MessageText = TextUtils.StringFormat(messageText, args);
                msg.AddException(exception);
                if (OnLogInformationEventHandler != null) OnLogInformationEventHandler(msg);
            }

            catch (Exception ex)
            {
                Log.LastChanceLog(ex);

            }
            return msg;
        }
Example #19
0
        /// <summary>
        /// Create a log message at the Critical log level. Message is exception.Message
        /// </summary>
        /// <param name="exception">Exception to write to Critical log</param>
        /// <returns>Created message that was submitted to log store</returns>
        public LogMessage Critical(Exception exception)
        {
            LogMessage msg = new LogMessage();
            try
            {
                if (IsCriticalEnabled == false) return null;


                msg.RuntimeContext = new RuntimeContext(RuntimeContextOptions.HttpRequestContext | RuntimeContextOptions.MachineContext);
                msg.Severity = MessageLevel.Critical;
                msg.MessageText = exception.Message;
                msg.AddException(exception);
                if (OnLogCriticalEventHandler != null) OnLogCriticalEventHandler(msg);
            }

            catch (Exception ex)
            {
                Log.LastChanceLog(ex);

            }
            return msg;
        }