private bool WriteToDiagnosticsTrace(EventWrittenEventArgs eventDescriptor, bool writeToConfigSource) { TraceEventType eventLevel = ServiceBusEventListener.GetEventLevel(eventDescriptor); ServiceBusEventListener.TraceEventChannel eventChannel = ServiceBusEventListener.GetEventChannel(eventDescriptor); if (writeToConfigSource && (eventChannel == ServiceBusEventListener.TraceEventChannel.Operational || eventChannel == ServiceBusEventListener.TraceEventChannel.Admin)) { string xmlFormattedString = this.ConvertMessageToXmlFormattedString(eventDescriptor); ServiceBusEventListener.traceSource.TraceEvent(eventLevel, eventDescriptor.EventId, xmlFormattedString); } if (this.EnableDiagnosticsTracing) { string str = this.ConvertMessageToXmlFormattedString(eventDescriptor); if (eventLevel == TraceEventType.Error || eventLevel == TraceEventType.Critical) { Trace.TraceError(str); } else if (eventLevel != TraceEventType.Warning) { Trace.TraceInformation(str); } else { Trace.TraceWarning(str); } } return(true); }
private string ConvertMessageToXmlFormattedString(EventWrittenEventArgs eventDescriptor) { StringBuilder stringBuilder = new StringBuilder(); using (XmlWriter xmlWriter = XmlWriter.Create(stringBuilder, ServiceBusEventListener.xmlWriterSettings)) { xmlWriter.WriteStartElement("Trc"); int eventId = eventDescriptor.EventId; xmlWriter.WriteAttributeString("Id", eventId.ToString(CultureInfo.InvariantCulture)); xmlWriter.WriteAttributeString("Ch", ServiceBusEventListener.GetEventChannel(eventDescriptor).ToString()); xmlWriter.WriteAttributeString("Lvl", ServiceBusEventListener.GetEventLevel(eventDescriptor).ToString()); xmlWriter.WriteAttributeString("Kw", eventDescriptor.Keywords.ToString("x")); DateTime utcNow = DateTime.UtcNow; xmlWriter.WriteAttributeString("UTC", utcNow.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fff'Z'", CultureInfo.InvariantCulture)); string item = this.messageDictionary[eventDescriptor.EventId]; if (item != null) { string str = string.Format(CultureInfo.InvariantCulture, item, ServiceBusEventListener.GetObjectAgsWithoutActivity(eventDescriptor.Payload)); xmlWriter.WriteAttributeString("Msg", SecurityElement.Escape(str)); xmlWriter.WriteEndElement(); } } string str1 = stringBuilder.ToString(); if (str1.Length > 31744) { string str2 = str1.Substring(0, 31744 - "#TRUNCATED#\" />".Length); CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { str2, "#TRUNCATED#\" />" }; str1 = string.Format(invariantCulture, "{0}{1}", objArray); } return(str1); }
private static void EnsureInitialized() { if (!ServiceBusEventListener.initialized) { ServiceBusEventListener.InitializeCore(); } }
public bool IsEnabled(byte level, long keywords) { ServiceBusEventListener.EnsureInitialized(); if (!this.EnableDiagnosticsTracing) { return(ServiceBusEventListener.useDiagnosticsTracing); } return(true); }
public bool IsEnabled() { ServiceBusEventListener.EnsureInitialized(); if (ServiceBusEventListener.useDiagnosticsTracing) { return(true); } return(this.EnableDiagnosticsTracing); }
public void WriteEvent(EventWrittenEventArgs eventDescriptor) { ServiceBusEventListener.EnsureInitialized(); if (ServiceBusEventListener.useDiagnosticsTracing) { this.WriteToDiagnosticsTrace(eventDescriptor, true); return; } if (this.EnableDiagnosticsTracing) { this.WriteToDiagnosticsTrace(eventDescriptor, false); } }
protected internal override void OnEventSourceCreated(EventSource eventSource) { if (eventSource != null && this.ProviderId == eventSource.Guid) { this.eventSource = eventSource; this.messageDictionary = ServiceBusEventListener.GetEventMessageDictionary(this.eventSource.GetType()); if (this.IsEnabled()) { base.EnableEvents(eventSource, EventLevel.Informational, (EventKeywords)((long)-1)); } } base.OnEventSourceCreated(eventSource); }