Esempio n. 1
0
 public override string ToString()
 {
     return(string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} - {9} - {10}{11}",
                          Source.Date.ToString("dd/MM/yyyy HH:mm:ss,fff").PadRight(24),
                          Enum.GetName(typeof(LogLevel), Type).Trim().PadRight(12),
                          Category.ToString().PadRight(14),
                          Source.IdentityName.PadRight(15),
                          Source.ProcessId.ToString().PadRight(6),
                          Source.ThreadId.ToString().PadRight(6),
                          Source.EventId.ToString().PadRight(4),
                          String.IsNullOrWhiteSpace(ActivityId)
                              ? string.Empty.PadRight(40)
                              : ActivityId.PadRight(40),
                          Source.TypeName,
                          Source.MethodName,
                          FullText,
                          Environment.NewLine));
 }
Esempio n. 2
0
        public void Format(LogEvent logEvent, TextWriter output)
        {
            try
            {
                var(Category, Application, Identity, ClassType, MethodName, ActivityId, ProcessId, ThreadId, Stacktrace, Properties) = Helper.ExtractEventInfo(logEvent);

                using (var properties = new StringWriter())
                    using (var messageText = new StringWriter())
                    {
                        MessageFormatter.Format(logEvent, messageText);
                        PropertyFormatter.Format(Properties, properties);

                        // Output the text.

                        output.WriteLine(string.Format("{0} {1} {2} {3} {4} {5} {6} {7} - {8} - {9} - {10}",
                                                       logEvent.Timestamp.ToString("dd/MM/yyyy HH:mm:ss,fff").PadRight(24),
                                                       MessageLogLevelMap[logEvent.Level].PadRight(13),
                                                       MessageCategoryMap[Category].PadRight(14),
                                                       Identity.PadRight(15),
                                                       ProcessId.ToString().PadRight(6),
                                                       ThreadId.ToString().PadRight(6),
                                                       ActivityId.PadRight(40),
                                                       ClassType,
                                                       MethodName,
                                                       messageText.ToString(),
                                                       properties.ToString()));

                        if (null != logEvent.Exception)
                        {
                            output.Write(logEvent.Exception.ToFormattedString());
                        }

                        if (!String.IsNullOrWhiteSpace(Stacktrace))
                        {
                            output.WriteLine(Stacktrace);
                        }
                    }
            }
            catch (Exception)
            {
            }
        }