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 static ServiceBusEventListener.TraceEventChannel GetEventChannel(EventWrittenEventArgs eventDescriptor)
        {
            ServiceBusEventListener.TraceEventChannel traceEventChannel = ServiceBusEventListener.TraceEventChannel.Debug;
            switch (eventDescriptor.Channel)
            {
            case 16:
            {
                traceEventChannel = ServiceBusEventListener.TraceEventChannel.Admin;
                break;
            }

            case 17:
            {
                traceEventChannel = ServiceBusEventListener.TraceEventChannel.Operational;
                break;
            }

            case 18:
            {
                traceEventChannel = ServiceBusEventListener.TraceEventChannel.Analytic;
                break;
            }

            case EventChannel.Application | EventChannel.Security | EventChannel.Setup:
            {
                traceEventChannel = ServiceBusEventListener.TraceEventChannel.Debug;
                break;
            }
            }
            return(traceEventChannel);
        }