Exemple #1
0
        public ExceptionData(string source, string errorPage, string url, Exception ex)
            : this()
        {
            TkDebug.AssertArgumentNull(ex, "ex", null);

            Exception = ex;
            Message   = ex.Message;
            Exception temp = ex;

            do
            {
                FullExceptionInfo info = new FullExceptionInfo();
                IExceptionInfo    intf = temp as IExceptionInfo;
                if (intf != null)
                {
                    intf.FillExceptionInfo(info);
                }
                else
                {
                    info.FillInfo(temp);
                }
                fList.Add(info);
                temp = temp.InnerException;
            } while (temp != null);

            Error = new ErrorInfo(source, errorPage, url);
        }
Exemple #2
0
        /// <summary>
        /// Display the session, or clear the existing session.
        /// </summary>
        /// <param name="session"></param>
        private void SetDisplaySession(ISession session)
        {
            m_Session = session;

            if (m_Session == null)
            {
                //clear our current display
                exceptionsGrid.DataSource = null;
                SetTitle("(No Data Yet) - Exceptions");
            }
            else
            {
                //display the session
                BindingList <IExceptionInfo> exceptionsToDisplay = new BindingList <IExceptionInfo>();

                //find all exceptions in our log messages regardless of severity.
                foreach (ILogMessage message in m_Session.GetMessages())
                {
                    if (message.HasException)
                    {
                        //we want just the inner-most exception for this example.
                        IExceptionInfo innermostException = message.Exception;
                        while (innermostException.InnerException != null)
                        {
                            innermostException = innermostException.InnerException;
                        }
                        exceptionsToDisplay.Add(innermostException);
                    }
                }

                //now bind this list to the grid.
                exceptionsGrid.DataSource = exceptionsToDisplay;
                SetTitle(string.Format("{0} Exceptions", exceptionsToDisplay.Count));
            }
        }
        /// <summary>
        /// Optimized deserialization of a LogMessagePacket based on the current packet definition
        /// </summary>
        public new void ReadFieldsFast(IFieldReader reader)
        {
            base.ReadFieldsFast(reader);

            m_ID           = reader.ReadGuid();
            m_Caption      = reader.ReadString();
            m_Severity     = (LogMessageSeverity)reader.ReadInt32();
            m_LogSystem    = reader.ReadString();
            m_CategoryName = reader.ReadString();
            m_UserName     = reader.ReadString();
            m_Description  = reader.ReadString();
            m_Details      = reader.ReadString();
            m_ThreadIndex  = reader.ReadInt32();
            m_ThreadId     = reader.ReadInt32();
            m_MethodName   = reader.ReadString();
            m_ClassName    = reader.ReadString();
            m_FileName     = reader.ReadString();
            m_LineNumber   = reader.ReadInt32();
            string[] typeNames         = reader.ReadStringArray();
            string[] messages          = reader.ReadStringArray();
            string[] sources           = reader.ReadStringArray();
            string[] stackTraces       = reader.ReadStringArray();
            Guid     applicationUserId = reader.ReadGuid();

            if (m_ThreadIndex == 0)
            {
                m_ThreadIndex = m_ThreadId; // Zero isn't legal, so it must not have had it.  Fall back to ThreadId.
            }
            if (applicationUserId != Guid.Empty)
            {
                ApplicationUser applicationUser;
                m_SessionPacketCache.Users.TryGetValue(applicationUserId, out applicationUser);
                UserPacket = applicationUser.Packet;
            }

            //these are supposed to be parallel arrays - assume they're all the same size.
            int arrayLength = typeNames.GetLength(0);
            var exceptions  = new IExceptionInfo[arrayLength]; // local holder to build it up

            IExceptionInfo lastException = null;

            for (int i = 0; i < arrayLength; i++)
            {
                IExceptionInfo exception = new ExceptionInfoPacket()
                {
                    TypeName   = typeNames[i],
                    Message    = messages[i],
                    Source     = sources[i],
                    StackTrace = stackTraces[i],
                };
                exceptions[i] = exception;
                if (lastException != null)
                {
                    ((ExceptionInfoPacket)lastException).InnerException = exception; //we are the inner exception to our parent.
                }
                lastException = exception;
            }

            m_ExceptionChain = exceptions; // Set the rehydrated ExceptionInfo[] array property
        }
        private static IExceptionInfo[] ExceptionToArray(Exception exception)
        {
            // This must accept a null Exception and never return a null, use empty array;
            if (exception == null)
            {
                return(new IExceptionInfo[0]);
            }

            int       count          = 1; // Otherwise, we have at least one
            Exception innerException = exception.InnerException;

            while (innerException != null) // Count up how big to make the array
            {
                count++;
                innerException = innerException.InnerException;
            }

            IExceptionInfo[] exceptions = new IExceptionInfo[count];

            //now start serializing them into the array...
            exceptions[0] = new ExceptionInfoPacket(exception);

            innerException = exception.InnerException;
            int index = 0;

            while (innerException != null)
            {
                index++;
                exceptions[index] = new ExceptionInfoPacket(innerException);
                ((ExceptionInfoPacket)exceptions[index - 1]).InnerException = exceptions[index]; //we are the inner exception to the previous one.
                innerException = innerException.InnerException;
            }
            return(exceptions);
        }
Exemple #5
0
        private static void Raise(IExceptionInfo exceptionInfo)
        {
            if (exceptionInfo == null)
            {
                return;                        // How do you throw an exception in throwing an exception
            }
            System.Exception ex = null;

            switch (exceptionInfo.Layer)
            {
            case Constants.ApplicationLayer.Application:
                ex =
                    new ApplicationException(I18nString.GetString(exceptionInfo.Message, exceptionInfo.Args),
                                             exceptionInfo.InnerException);
                break;

            case Constants.ApplicationLayer.Infrastructure:
                ex =
                    new InfrastructureException(I18nString.GetString(exceptionInfo.Message, exceptionInfo.Args),
                                                exceptionInfo.InnerException);
                break;


            case Constants.ApplicationLayer.DataAccess:
                ex =
                    new DataAccessException(I18nString.GetString(exceptionInfo.Message, exceptionInfo.Args),
                                            exceptionInfo.InnerException);
                break;

            case Constants.ApplicationLayer.BusinessEnitity:
                ex =
                    new BusinessEntityException(I18nString.GetString(exceptionInfo.Message, exceptionInfo.Args),
                                                exceptionInfo.InnerException);
                break;

            case Constants.ApplicationLayer.BusinessLogic:
                ex =
                    new BusinessLogicException(I18nString.GetString(exceptionInfo.Message, exceptionInfo.Args),
                                               exceptionInfo.InnerException, exceptionInfo.Severity);


                break;

            default:
                return;
            }

            if (ex != null)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Normalize the exception pointers to a single list.
        /// </summary>
        /// <param name="exception"></param>
        /// <returns></returns>
        public static IList <IExceptionInfo> ExceptionsList(IExceptionInfo exception)
        {
            List <IExceptionInfo> exceptions = new List <IExceptionInfo>();

            IExceptionInfo innerException = exception;

            while (innerException != null)
            {
                exceptions.Add(innerException);
                innerException = innerException.InnerException;
            }

            return(exceptions);
        }
Exemple #7
0
        public void HandleException(Guid id, IExceptionInfo exceptionInfo)
        {
            var logger = _loggerRepository.GetAll(a => a.PrivateToken == id).FirstOrDefault();

            if (logger.IsNullOrEmpty())
            {
                throw new InvalidTokenException(id);
            }

            logger.AddException(Mapper.Map <ExceptionInfo>(exceptionInfo));

            _loggerRepository.Update(logger);

            SendResponse(logger.Name, logger.UserLoggers, logger.Exceptions.Last());
        }
        protected override void ExportLogMessage(ISession session, ILogMessage message)
        {
            if (message.Severity == LogMessageSeverity.Verbose)
            {
                Write("{0} {1}\r\n", message.Timestamp, message.Caption.Trim());
            }
            else
            {
                var severity = message.Severity.ToString();
                if (severity.StartsWith("Info") || severity.StartsWith("Warn"))
                {
                    severity = severity.Substring(0, 4);
                }
                else
                {
                    severity = severity.ToUpperInvariant();
                }

                Write("{0} {2} {1}\r\n", message.Timestamp, message.Caption.Trim(), severity);
            }
            if (string.IsNullOrEmpty(message.Description) == false)
            {
                Write("{0}\r\n", message.Description.Trim());
            }

            IExceptionInfo currentException = message.Exception;

            if (currentException != null)
            {
                if (Config.IncludeExceptionDetails)
                {
                    var label = "EXCEPTION";
                    while (currentException != null)
                    {
                        Write("{0}: {1} - {2}\r\n", label, currentException.TypeName, currentException.Message.Trim());
                        currentException = currentException.InnerException;
                        label            = "INNER EXCEPTION";
                    }
                }
                else
                {
                    Write("{0}: {1}\r\n", currentException.TypeName, currentException.Message.Trim());
                }
                WriteLine();
            }
        }
        /// <summary>
        /// Analyze the provided session.
        /// </summary>
        /// <param name="session">The session to be analyzed</param>
        private void ExportSession(ISession session)
        {
            //lets have fun writing an entire session out to a text file.
            string filePath = m_OutputPath;
            string fileName = session.Id + ".txt";

            if (Directory.Exists(filePath) == false)
            {
                Directory.CreateDirectory(filePath);
            }

            using (StreamWriter writer = new StreamWriter(Path.Combine(filePath, fileName)))
            {
                writer.Write("SESSION SUMMARY:\r\n================================================================================================\r\n");
                writer.Write("Product: {0} App: {1}\r\n", session.Summary.Product, session.Summary.Application);
                writer.Write("Criticals: {0} Errors: {1} Warnings: {2} Messages: {3}\r\n", session.CriticalCount, session.ErrorCount, session.WarningCount, session.MessageCount);
                writer.Write("Session Start: {0} End: {1}  Duration: {2}\r\n", session.Summary.StartDateTime, session.Summary.EndDateTime, session.Summary.Duration);
                writer.Write("App Description: {0}\r\n", session.Summary.ApplicationDescription);
                writer.Write("App Type: {0}\r\n", session.Summary.ApplicationType);
                writer.Write("App Version: {0}\r\n", session.Summary.ApplicationVersion);
                writer.Write("Agent Version: {0}\r\n", session.Summary.AgentVersion);
                writer.Write("Command Line: {0}\r\n", session.Summary.CommandLine);
                writer.Write("User: {0}\r\n", session.Summary.FullyQualifiedUserName);
                writer.Write("Computer: {0}\r\n", session.Summary.HostName);
                writer.Write("OS Details: {0}\r\n", session.Summary.OSFullNameWithServicePack);
                writer.Write("DNS Domain: {0}\r\n", session.Summary.DnsDomainName);
                writer.Write("Processors: {0}\r\n", session.Summary.Processors);
                writer.Write("Memory: {0}\r\n", session.Summary.MemoryMB);
                writer.Write("OS Boot Modes: {0}\r\n", session.Summary.OSBootMode);
                writer.Write("OS Architecture: {0}\r\n", session.Summary.OSArchitecture);
                writer.Write("Process Architecture: {0}\r\n", session.Summary.RuntimeArchitecture);
                writer.Write(".NET Runtime Version: {0}\r\n", session.Summary.RuntimeVersion);
                writer.Write("Screen: {0}x{1}x{2}\r\n", session.Summary.ScreenWidth, session.Summary.ScreenHeight, session.Summary.ColorDepth);
                writer.Write("Time Zone: {0}\r\n", session.Summary.TimeZoneCaption);
                writer.Write("User Interactive: {0}\r\n", session.Summary.UserInteractive);
                writer.Write("Terminal Server: {0}\r\n", session.Summary.TerminalServer);


                writer.Write("\r\n\r\nTHREADS:\r\n================================================================================================\r\n");
                foreach (IThreadInfo thread in session.Threads)
                {
                    writer.Write("ID: {0} Name: {1} Background: {2} Thread Pool: {3}\r\n",
                                 thread.ThreadId, thread.ThreadName, thread.IsBackground, thread.IsThreadPoolThread);
                }
                writer.Write("================================================================================================\r\n");

                writer.Write("\r\n\r\nASSEMBLIES:\r\n================================================================================================\r\n");
                foreach (IAssemblyInfo assembly in session.Assemblies)
                {
                    writer.Write("Name: {0} Version: {1} File Version: {2} Architecture: {3} GAC: {4} Culture: {6}\r\n  Loaded at: {7}\r\n  Location: {5}\r\n",
                                 assembly.Name, assembly.Version, assembly.FileVersion, assembly.ProcessorArchitecture, assembly.GlobalAssemblyCache, assembly.Location, assembly.CultureName, assembly.LoadedTimeStamp);
                }
                writer.Write("================================================================================================\r\n");

                writer.Write("\r\n\r\nMESSAGES:\r\n================================================================================================\r\n");
                foreach (ILogMessage message in session.GetMessages())
                {
                    writer.Write("\r\n{1} {2} (Sequence {0}) Logged from: {3}\r\nCategory: {4}\r\n",
                                 message.Sequence, message.Timestamp, message.Severity.ToString().ToUpperInvariant(), message.LogSystem, message.CategoryName);

                    if (string.IsNullOrEmpty(message.ClassName) == false)
                    {
                        writer.Write("Class: {0} Method: {1}\r\n", message.ClassName, message.MethodName);
                    }

                    if (string.IsNullOrEmpty(message.FileName) == false)
                    {
                        writer.Write("File: {0} Line: {1}\r\n", message.FileName, message.LineNumber);
                    }

                    writer.Write("Thread Id: {0} Name: {1}\r\n", message.ThreadId, message.ThreadName);
                    writer.Write("User: {0}\r\n", message.UserName);


                    writer.Write("Caption: {0}\r\n", message.Caption);

                    if (string.IsNullOrEmpty(message.Description) == false)
                    {
                        writer.Write("{0}\r\n", message.Description);
                    }

                    writer.WriteLine();

                    IExceptionInfo currentException = message.Exception;
                    if (currentException != null)
                    {
                        writer.Write("Exceptions:\r\n------------------------------------------------------------------------------------------------\r\n");
                        while (currentException != null)
                        {
                            writer.Write("Exception: {0}\r\nMessage: {1}\r\nSource: {2}\r\nStack Trace:\r\n{3}\r\n",
                                         currentException.TypeName, currentException.Message, currentException.Source, currentException.StackTrace);
                            currentException = currentException.InnerException;
                        }
                        writer.Write("------------------------------------------------------------------------------------------------\r\n");
                    }

                    if (string.IsNullOrEmpty(message.Details) == false)
                    {
                        writer.Write("Exceptions:\r\n------------------------------------------------------------------------------------------------\r\n");
                        writer.Write(message.Details);
                        writer.Write("------------------------------------------------------------------------------------------------\r\n");
                    }
                }
                writer.Write("================================================================================================\r\n");
            }
        }
Exemple #10
0
        public string GetLogMessageDetails()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("{0}", GetLogMessageSummary());

            if (!string.IsNullOrEmpty(Message.Description))
            {
                builder.AppendFormat("{0}\r\n", Message.Description);
            }

            if (!string.IsNullOrEmpty(Message.Details))
            {
                builder.AppendFormat("\r\nAdditional Details:\r\n");
                AppendDivider(builder);
                builder.AppendFormat("{0}\r\n", Message.Details);
                AppendDivider(builder);
            }

            // Include message source info when present, but only for warnings, errors and critical messages
            if (!string.IsNullOrEmpty(Message.CategoryName))
            {
                builder.AppendFormat("Category: {0}\r\n", Message.CategoryName);
            }

            if (!string.IsNullOrEmpty(Message.ClassName))
            {
                builder.AppendFormat("In: {0}.{1}\r\n", Message.ClassName, Message.MethodName);
            }

            if (!string.IsNullOrEmpty(Message.FileName))
            {
                builder.AppendFormat("At: Line {0}\r\n" +
                                     "{1}\r\n",
                                     Message.LineNumber,
                                     Message.FileName);
            }

            if (Message.Exception != null)
            {
                IExceptionInfo exception = Message.Exception;
                if (exception != null)
                {
                    builder.AppendFormat("\r\nException Details:\r\n");
                    AppendDivider(builder);
                    while (exception != null)
                    {
                        builder.AppendFormat("EXCEPTION: {0}\r\n" +
                                             "Source: {1}\r\n" +
                                             "Message: {2}\r\n" +
                                             "Stack Trace:\r\n{3}\r\n\r\n",
                                             exception.TypeName,
                                             exception.Source,
                                             exception.Message,
                                             exception.StackTrace);
                        exception = exception.InnerException;
                    }
                    AppendDivider(builder);
                }
            }

            return(builder.ToString());
        }
        protected override void ExportLogMessage(ISession session, ILogMessage message)
        {
            WriteLine();
            if (message.Severity == LogMessageSeverity.Verbose)
            {
                Write("{0} {1}\r\n", message.Timestamp, message.Caption.Trim());
            }
            else
            {
                var severity = message.Severity.ToString();
                if (severity.StartsWith("Info") || severity.StartsWith("Warn"))
                {
                    severity = severity.Substring(0, 4);
                }
                else
                {
                    severity = severity.ToUpperInvariant();
                }

                Write("{0} {2} {1}\r\n", message.Timestamp, message.Caption.Trim(), severity);
            }
            if (string.IsNullOrEmpty(message.Description) == false)
            {
                Write("{0}\r\n", message.Description.Trim());
            }
            Write("Category: {0} from {1}", message.CategoryName, message.LogSystem);

            if (string.IsNullOrEmpty(message.ClassName) == false)
            {
                Write("  {0}.{1}", message.ClassName, message.MethodName);
            }

            if (string.IsNullOrEmpty(message.FileName) == false)
            {
                Write(" in {0} ({1})", message.FileName, message.LineNumber);
            }
            WriteLine();

            Write("Thread: {0} ({1}) for {2}\r\n", message.ThreadName, message.ThreadId, message.UserName);

            IExceptionInfo currentException = message.Exception;

            if (currentException != null)
            {
                if (Config.IncludeExceptionDetails)
                {
                    var label = "EXCEPTION";
                    while (currentException != null)
                    {
                        Write("{0}: {1} - {2} from {3}\r\nStack Trace:\r\n{4}\r\n",
                              label, currentException.TypeName, currentException.Message.Trim(),
                              currentException.Source, currentException.StackTrace);
                        currentException = currentException.InnerException;
                        label            = "INNER EXCEPTION";
                    }
                }
                else
                {
                    while (currentException != null)
                    {
                        Write("{0}: {1}\r\n", currentException.TypeName, currentException.Message.Trim());
                        currentException = currentException.InnerException;
                    }
                }
                WriteLine();
            }
        }
Exemple #12
0
        private void RecordException(AspNetDeployEntities entities, ExceptionEntry parentException, IExceptionInfo lastException, MachinePublicationLog machinePublicationLog)
        {
            ExceptionEntry exceptionEntry = new ExceptionEntry();

            machinePublicationLog.Exception = exceptionEntry;
            exceptionEntry.Message          = lastException.Message;
            exceptionEntry.Source           = lastException.Source;
            exceptionEntry.StackTrace       = lastException.StackTrace;
            exceptionEntry.TypeName         = lastException.TypeName;
            entities.ExceptionEntry.Add(exceptionEntry);

            if (parentException != null)
            {
                parentException.InnerExceptionEntry = exceptionEntry;
            }
            else
            {
                AspNetDeployExceptionEntry aspNetDeployExceptionEntry = new AspNetDeployExceptionEntry();
                aspNetDeployExceptionEntry.TimeStamp      = DateTime.UtcNow;
                aspNetDeployExceptionEntry.ExceptionEntry = exceptionEntry;
                entities.AspNetDeployExceptionEntry.Add(aspNetDeployExceptionEntry);
            }

            foreach (IExceptionDataInfo exceptionDataInfo in lastException.ExceptionData)
            {
                ExceptionEntryData data = new ExceptionEntryData();
                data.ExceptionEntry = exceptionEntry;
                data.IsProperty     = exceptionDataInfo.IsProperty;
                data.Name           = exceptionDataInfo.Name;
                data.Value          = exceptionDataInfo.Value;
                entities.ExceptionEntryData.Add(data);
            }

            if (lastException.InnerException != null)
            {
                this.RecordException(entities, exceptionEntry, lastException.InnerException, machinePublicationLog);
            }
        }
Exemple #13
0
        private void LogMachinePublicationStep(MachinePublication machinePublication, DeploymentStep deploymentStep, AspNetDeployEntities entities, MachinePublicationLogEvent @event, IExceptionInfo lastException = null)
        {
            MachinePublicationLog machinePublicationLog = new MachinePublicationLog();

            machinePublicationLog.CreatedDate        = DateTime.UtcNow;
            machinePublicationLog.MachinePublication = machinePublication;
            machinePublicationLog.Event            = @event;
            machinePublicationLog.DeploymentStepId = deploymentStep.Id;
            entities.MachinePublicationLog.Add(machinePublicationLog);

            if (lastException != null)
            {
                this.RecordException(entities, null, lastException, machinePublicationLog);
            }

            entities.SaveChanges();
        }
        void IPacket.ReadFields(PacketDefinition definition, SerializedPacket packet)
        {
            switch (definition.Version)
            {
            case 1:
            case 2:     //two just adds fields.
            case 3:     //three just adds one field.
                packet.GetField("ID", out m_ID);
                packet.GetField("Caption", out m_Caption);

                // Hmmm, it's tricky to handle the enum with an out parameter; use a temporary int and cast it.
                int severity;
                packet.GetField("Severity", out severity);
                m_Severity = (LogMessageSeverity)severity;

                packet.GetField("LogSystem", out m_LogSystem);
                packet.GetField("CategoryName", out m_CategoryName);
                packet.GetField("UserName", out m_UserName);

                if (definition.Version >= 2)
                {
                    packet.GetField("Description", out m_Description);
                    packet.GetField("Details", out m_Details);
                }

                // These have now been fully integrated here from the former CallInfoPacket
                packet.GetField("ThreadId", out m_ThreadId);
                packet.GetField("MethodName", out m_MethodName);
                packet.GetField("ClassName", out m_ClassName);
                packet.GetField("FileName", out m_FileName);
                packet.GetField("LineNumber", out m_LineNumber);

                if (definition.Fields.ContainsKey("ThreadIndex"))
                {
                    packet.GetField("ThreadIndex", out m_ThreadIndex);
                    if (m_ThreadIndex == 0)
                    {
                        m_ThreadIndex = m_ThreadId;     // Zero isn't legal, so it must not have had it.  Fall back to ThreadId.
                    }
                }
                else
                {
                    m_ThreadIndex = m_ThreadId;     // Oops, older code doesn't have it, so use the ThreadId to fake it.
                }

                //we now know enough to get our thread info packet (if we don't, we can't re-serialize ourselves)
                ThreadInfo threadInfo;
                if (m_SessionPacketCache.Threads.TryGetValue(m_ThreadIndex, out threadInfo))
                {
                    ThreadInfoPacket = threadInfo.Packet;
                }

                // Now the Exception info...

                string[] typeNames;
                string[] messages;
                string[] sources;
                string[] stackTraces;

                packet.GetField("TypeNames", out typeNames);
                packet.GetField("Messages", out messages);
                packet.GetField("Sources", out sources);
                packet.GetField("StackTraces", out stackTraces);

                //these are supposed to be parallel arrays - assume they're all the same size.
                int arrayLength             = typeNames.GetLength(0);
                IExceptionInfo[] exceptions = new IExceptionInfo[arrayLength];     // local holder to build it up

                IExceptionInfo lastException = null;
                for (int i = 0; i < arrayLength; i++)
                {
                    IExceptionInfo exception = new ExceptionInfoPacket()
                    {
                        TypeName   = typeNames[i],
                        Message    = messages[i],
                        Source     = sources[i],
                        StackTrace = stackTraces[i]
                    };
                    exceptions[i] = exception;
                    if (lastException != null)
                    {
                        ((ExceptionInfoPacket)lastException).InnerException = exception;     //we are the inner exception to our parent.
                    }
                    lastException = exception;
                }

                m_ExceptionChain = exceptions;     // Set the rehydrated ExceptionInfo[] array property

                if (definition.Version >= 3)
                {
                    Guid applicationUserId;
                    packet.GetField("ApplicationUserId", out applicationUserId);

                    //we now know enough to get our user packet now if it was specified..
                    ApplicationUser applicationUser;
                    if (m_SessionPacketCache.Users.TryGetValue(applicationUserId, out applicationUser))
                    {
                        UserPacket = applicationUser.Packet;
                    }
                }

                break;
            }
        }
        protected override void ExportLogMessage(ISession session, ILogMessage message)
        {
            WriteLine();
            if (message.Severity == LogMessageSeverity.Verbose)
            {
                Write("{1} (Seq# {0}) Logged from: {2}  Category: {3}\r\n",
                      message.Sequence, message.Timestamp, message.LogSystem, message.CategoryName);
            }
            else
            {
                var severity = message.Severity.ToString();
                if (severity.StartsWith("Info") || severity.StartsWith("Warn"))
                {
                    severity = severity.Substring(0, 4);
                }
                else
                {
                    severity = severity.ToUpperInvariant();
                }

                Write("\r\n{1} {4} (Seq# {0}) Logged from: {2}\r\nCategory: {3}\r\n",
                      message.Sequence, message.Timestamp, message.LogSystem, message.CategoryName, severity);
            }

            if (string.IsNullOrEmpty(message.ClassName) == false)
            {
                Write("Class: {0} Method: {1}\r\n", message.ClassName, message.MethodName);
            }

            if (string.IsNullOrEmpty(message.FileName) == false)
            {
                Write("File: {0} Line: {1}\r\n", message.FileName, message.LineNumber);
            }

            Write("Thread Id: {0} Name: {1}  User: {2}\r\n", message.ThreadId, message.ThreadName, message.UserName);

            Write("Caption: {0}\r\n", message.Caption.Trim());

            if (string.IsNullOrEmpty(message.Description) == false)
            {
                Write("{0}\r\n", message.Description.Trim());
            }

            if (string.IsNullOrEmpty(message.Details) == false)
            {
                Write(
                    "Details:\r\n------------------------------------------------------------------------------------------------\r\n");
                Write(message.Details.Trim());
                Write(
                    "\r\n------------------------------------------------------------------------------------------------\r\n");
            }

            IExceptionInfo currentException = message.Exception;

            if (currentException != null)
            {
                if (Config.IncludeExceptionDetails)
                {
                    Write(
                        "Exceptions:\r\n------------------------------------------------------------------------------------------------\r\n");
                    var label = "EXCEPTION";
                    while (currentException != null)
                    {
                        Write("{0}: {1}\r\nMessage: {2}\r\nSource: {3}\r\nStack Trace:\r\n{4}\r\n",
                              label, currentException.TypeName, currentException.Message.Trim(),
                              currentException.Source, currentException.StackTrace);
                        currentException = currentException.InnerException;
                        label            = "INNER EXCEPTION";
                    }
                    if (currentException != null)
                    {
                        Write(
                            "------------------------------------------------------------------------------------------------\r\n");
                    }
                }
                else
                {
                    var label = "EXCEPTION";
                    while (currentException != null)
                    {
                        Write("{0}: {1} - {2}\r\n", label, currentException.TypeName, currentException.Message.Trim());
                        currentException = currentException.InnerException;
                        label            = "INNER EXCEPTION";
                    }
                }
            }

            Write(
                "================================================================================================\r\n");
        }