Exemplo n.º 1
0
 /// <summary>
 /// Add stack trace information into message builder
 /// </summary>
 /// <param name="builder">string builder</param>
 /// <param name="stackTrace">stack trace</param>
 /// <param name="title">stack trace title</param>
 /// <param name="fileLabel">file label</param>
 /// <param name="lineLable">line label</param>
 /// <param name="columnLabel">column label</param>
 public static void AppendStackTraceInformation(
     StringBuilder builder,
     StackTrace stackTrace,
     string title       = DefaultStackTraceTitle,
     string fileLabel   = DefaultFileLabel,
     string lineLable   = DefaultLineLabel,
     string columnLabel = DefaultColumnLabel)
 {
     if (stackTrace != null)
     {
         var frames = stackTrace.GetFrames();
         if (!frames.IsNullOrEmpty())
         {
             builder.AppendLine($"{title}:");
             foreach (var frame in frames)
             {
                 builder.Append('\t');
                 DiagnosticUtilities.AppendMethodInformation(builder, frame, fileLabel, lineLable, columnLabel);
                 builder.AppendLine();
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Write event log
        /// </summary>
        /// <param name="eventSource">event source name</param>
        /// <param name="eventId">event id</param>
        /// <param name="eventLevel">event level</param>
        /// <param name="message">detail event information</param>
        /// <param name="eventTime">the time the event happened</param>
        /// <param name="stackTrace">stack trace</param>
        /// <param name="runtimeInformation">additional runtime information</param>
        public void Write(
            string eventSource,
            int eventId,
            EventLevel eventLevel,
            string message,
            DateTime eventTime,
            StackTrace stackTrace,
            IReadOnlyDictionary <string, object> runtimeInformation)
        {
            var builder = new StringBuilder(TracePrefix);

            builder.AppendLine($"[Source:{eventSource}][id:{eventId}][Level:{eventLevel}][Time:{eventTime.ToString()}]");
            if (!string.IsNullOrEmpty(message))
            {
                builder.AppendLine("Message:");
                builder.AppendLine($"\t{message}");
            }

            DiagnosticUtilities.AppendStackTraceInformation(builder, stackTrace);
            DiagnosticUtilities.AddRuntimeInformation(builder, runtimeInformation);

            Trace.WriteLine(builder.ToString());
        }