/// <summary>
 /// Writes a trace event message to the trace listeners in the Listeners collection using the specified event type and event identifier.
 /// </summary>
 /// <param name="traceSource">The 'TraceSource' instance.</param>
 /// <param name="traceEventType">One of the enumeration values that specifies the event type of the trace data.</param>
 /// <param name="message">The informative message to write.</param>
 /// <param name="duration">The trace event duration.</param>
 /// <param name="status">One of the enumeration values that specifies the event status of the trace event.</param>
 /// <param name="exception">THe exception that to trace as part of the trace event.</param>
 /// <param name="data">The trace data.</param>
 /// <param name="methodName">The calling method where the log originated from</param>
 internal static void TraceEventInternal(this TraceSource traceSource, TraceEventType traceEventType, string message, TimeSpan duration, TraceStatus status, Exception exception, IEnumerable <KeyValuePair <string, object> > data, string methodName)
 {
     try
     {
         if (!TraceSourceExt.ShouldTrace(traceSource, traceEventType))
         {
             return;
         }
         TraceEventEntry traceEventEntry = TraceEventEntryBuilder.IncludeEnvironmentData(new TraceEventEntry()
         {
             ApplicationName = traceSource.Name,
             EventData       = TraceSourceExt.EventDataBuilder.CreateTraceEventData(exception, data),
             EventDuration   = duration,
             EventKeys       = TraceSourceExt.EventDataBuilder.CreateEventKeys(TraceSourceExt.GetKeys()),
             EventType       = traceEventType.ToString(),
             Message         = message,
             MethodName      = methodName,
             Status          = (int)status
         });
         traceSource.TraceData(traceEventType, 0, (object)traceEventEntry);
         traceSource.Flush();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Trace.WriteLine(string.Format("An error occurred while tracing. {0}", (object)ex.Message));
     }
 }
 /// <summary>
 /// Writes a trace event message to the trace listeners in the Listeners collection using the specified event type and event identifier.
 /// </summary>
 /// <param name="traceSource">The 'TraceSource' instance.</param>
 /// <param name="traceEventType">One of the enumeration values that specifies the event type of the trace data.</param>
 /// <param name="message">The informative message to write.</param>
 /// <param name="duration">The trace event duration.</param>
 /// <param name="status">One of the enumeration values that specifies the event status of the trace event.</param>
 /// <param name="exception">THe exception that to trace as part of the trace event.</param>
 /// <param name="data">The trace data.</param>
 /// <param name="methodName">The calling method where the log originated from</param>
 private static void TraceEventWithDataArrayInternal(this TraceSource traceSource, TraceEventType traceEventType, string message, TimeSpan duration, TraceStatus status, Exception exception, object[] data, string methodName)
 {
     try
     {
         if (!TraceSourceExt.ShouldTrace(traceSource, traceEventType))
         {
             return;
         }
         ICollection <KeyValuePair <string, object> > items = RawBlobParser.ParseItems((IList <object>)data);
         TraceSourceExt.TraceEventInternal(traceSource, traceEventType, message, duration, status, exception, (IEnumerable <KeyValuePair <string, object> >)items, methodName);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Trace.WriteLine(string.Format("An error occurred while tracing. {0}", (object)ex.Message));
     }
 }
 public static void TraceException(this TraceSource traceSource, string message, Exception exception, [CallerMemberName] string methodName = null)
 {
     TraceSourceExt.TraceEventInternal(traceSource, TraceEventType.Error, message, TimeSpan.Zero, TraceStatus.Failed, exception, (IEnumerable <KeyValuePair <string, object> >)null, methodName);
 }
 /// <summary>
 /// Writes a exception trace event message to the trace listeners in the Listeners collection using the specified event type and event identifier.
 /// </summary>
 /// <param name="traceSource">The 'TraceSource' instance.</param>
 /// <param name="exception">The exception data.</param>
 /// <param name="traceEventType">One of the enumeration values that specifies the event type of the trace data.</param>
 /// <param name="message">The informative message to write.</param>
 /// <param name="duration">The trace event duration.</param>
 /// <param name="status">One of the enumeration values that specifies the event status of the trace event.</param>
 /// <param name="data">The trace data.  The keys will be the Trace Data type and the values will be logged as the Trace Data.</param>
 /// <param name="methodName">The calling method where the log originated from</param>
 public static void TraceException(this TraceSource traceSource, Exception exception, TraceEventType traceEventType, string message, TimeSpan duration, TraceStatus status, Dictionary <string, object> data, [CallerMemberName] string methodName = null)
 {
     TraceSourceExt.TraceEventInternal(traceSource, traceEventType, message, duration, status, exception, (IEnumerable <KeyValuePair <string, object> >)data, methodName);
 }
 /// <summary>Posts a trace event to the TraceListener.</summary>
 /// <param name="traceSource">The 'TraceSource' instance.</param>
 /// <param name="message">The informative message to write.</param>
 /// <param name="methodName">The calling method where the log originated from</param>
 public static void TraceEvent(this TraceSource traceSource, string message, [CallerMemberName] string methodName = null)
 {
     TraceSourceExt.TraceEventInternal(traceSource, TraceEventType.Verbose, message, TimeSpan.Zero, TraceStatus.Request, (Exception)null, (IEnumerable <KeyValuePair <string, object> >)null, methodName);
 }