示例#1
0
        static void InitializeMessageTraceSource()
        {
            try
            {
                MessageLogger.attemptedTraceSourceInitialization = true;
                PiiTraceSource tempSource = new PiiTraceSource(MessageLogger.MessageTraceSourceName, DiagnosticUtility.EventSourceName);
                tempSource.Switch.Level = SourceLevels.Information;
                tempSource.Listeners.Remove(MessageLogger.DefaultTraceListenerName);
                if (tempSource.Listeners.Count > 0)
                {
                    AppDomain.CurrentDomain.DomainUnload       += new EventHandler(ExitOrUnloadEventHandler);
                    AppDomain.CurrentDomain.ProcessExit        += new EventHandler(ExitOrUnloadEventHandler);
                    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExitOrUnloadEventHandler);
                }
                else
                {
                    tempSource = null;
                }

                MessageLogger.messageTraceSource = tempSource;
            }
            catch (System.Configuration.ConfigurationErrorsException)
            {
                throw;
            }
#pragma warning suppress 56500 // covered by FxCOP
            catch (SecurityException securityException)
            {
                // message logging is not support in PT, write the trace
                MessageLogger.inPartialTrust = true;
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning,
                                            TraceCode.TraceHandledException,
                                            SR.GetString(SR.PartialTrustMessageLoggingNotEnabled),
                                            null,
                                            securityException);
                }
                // also write to event log
                LogNonFatalInitializationException(
                    new SecurityException(
                        SR.GetString(SR.PartialTrustMessageLoggingNotEnabled),
                        securityException));
            }
            catch (Exception e)
            {
                MessageLogger.messageTraceSource = null;

                if (Fx.IsFatal(e))
                {
                    throw;
                }

                LogNonFatalInitializationException(e);
            }
        }
 private static void ExitOrUnloadEventHandler(object sender, EventArgs e)
 {
     lock (syncObject)
     {
         if (MessageTraceSource != null)
         {
             MessageTraceSource.Close();
             messageTraceSource = null;
         }
     }
 }
示例#3
0
 static void ExitOrUnloadEventHandler(object sender, EventArgs e)
 {
     lock (MessageLogger.syncObject)
     {
         if (null != MessageLogger.MessageTraceSource)
         {
             //Flush is called automatically on close by StreamWriter
             MessageLogger.MessageTraceSource.Close();
             MessageLogger.messageTraceSource = null;
         }
     }
 }
        private void CreateTraceSource()
        {
            PiiTraceSource piiTraceSource = null;

            if (this.traceSourceType == TraceSourceKind.PiiTraceSource)
            {
                piiTraceSource = new PiiTraceSource(this.TraceSourceName, this.eventSourceName, SourceLevels.Off);
            }
            else
            {
                piiTraceSource = new System.ServiceModel.Diagnostics.DiagnosticTraceSource(this.TraceSourceName, this.eventSourceName, SourceLevels.Off);
            }
            this.UnsafeRemoveDefaultTraceListener(piiTraceSource);
            this.TraceSource = piiTraceSource;
        }
        void CreateTraceSource()
        {
            PiiTraceSource tempSource = null;

            if (this.traceSourceType == TraceSourceKind.PiiTraceSource)
            {
                tempSource = new PiiTraceSource(this.TraceSourceName, this.EventSourceName, LegacyDiagnosticTrace.DefaultLevel);
            }
            else
            {
                tempSource = new DiagnosticTraceSource(this.TraceSourceName, this.EventSourceName, LegacyDiagnosticTrace.DefaultLevel);
            }

            SetTraceSource(tempSource);
        }
 private static void InitializeMessageTraceSource()
 {
     try
     {
         attemptedTraceSourceInitialization = true;
         PiiTraceSource source = new PiiTraceSource("System.ServiceModel.MessageLogging", "System.ServiceModel 4.0.0.0")
         {
             Switch = { Level = SourceLevels.Information }
         };
         source.Listeners.Remove("Default");
         if (source.Listeners.Count > 0)
         {
             AppDomain.CurrentDomain.DomainUnload       += new EventHandler(MessageLogger.ExitOrUnloadEventHandler);
             AppDomain.CurrentDomain.ProcessExit        += new EventHandler(MessageLogger.ExitOrUnloadEventHandler);
             AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MessageLogger.ExitOrUnloadEventHandler);
         }
         else
         {
             source = null;
         }
         messageTraceSource = source;
     }
     catch (ConfigurationErrorsException)
     {
         throw;
     }
     catch (SecurityException exception)
     {
         inPartialTrust = true;
         if (DiagnosticUtility.ShouldTraceWarning)
         {
             TraceUtility.TraceEvent(TraceEventType.Warning, 0x20004, System.ServiceModel.SR.GetString("PartialTrustMessageLoggingNotEnabled"), null, exception);
         }
         LogNonFatalInitializationException(new SecurityException(System.ServiceModel.SR.GetString("PartialTrustMessageLoggingNotEnabled"), exception));
     }
     catch (Exception exception2)
     {
         messageTraceSource = null;
         if (Fx.IsFatal(exception2))
         {
             throw;
         }
         LogNonFatalInitializationException(exception2);
     }
 }
 private void UnsafeRemoveDefaultTraceListener(PiiTraceSource piiTraceSource)
 {
     piiTraceSource.Listeners.Remove("Default");
 }
        void CreateTraceSource()
        {
            PiiTraceSource tempSource = null;
            if (this.traceSourceType == TraceSourceKind.PiiTraceSource)
            {
                tempSource = new PiiTraceSource(this.TraceSourceName, this.EventSourceName, LegacyDiagnosticTrace.DefaultLevel);
            }
            else
            {
                tempSource = new DiagnosticTraceSource(this.TraceSourceName, this.EventSourceName, LegacyDiagnosticTrace.DefaultLevel);
            }

            SetTraceSource(tempSource);
        }
 static void ExitOrUnloadEventHandler(object sender, EventArgs e)
 {
     lock (MessageLogger.syncObject)
     {
         if (null != MessageLogger.MessageTraceSource)
         {
             //Flush is called automatically on close by StreamWriter
             MessageLogger.MessageTraceSource.Close();
             MessageLogger.messageTraceSource = null;
         }
     }
 }
        static void InitializeMessageTraceSource()
        {
            try
            {
                MessageLogger.attemptedTraceSourceInitialization = true;
                PiiTraceSource tempSource = new PiiTraceSource(MessageLogger.MessageTraceSourceName, DiagnosticUtility.EventSourceName);
                tempSource.Switch.Level = SourceLevels.Information;
                tempSource.Listeners.Remove(MessageLogger.DefaultTraceListenerName);
                if (tempSource.Listeners.Count > 0)
                {
                    AppDomain.CurrentDomain.DomainUnload += new EventHandler(ExitOrUnloadEventHandler);
                    AppDomain.CurrentDomain.ProcessExit += new EventHandler(ExitOrUnloadEventHandler);
                    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExitOrUnloadEventHandler);
                }
                else
                {
                    tempSource = null;
                }

                MessageLogger.messageTraceSource = tempSource;
            }
            catch (System.Configuration.ConfigurationErrorsException)
            {
                throw;
            }
#pragma warning suppress 56500 // covered by FxCOP
            catch (SecurityException securityException)
            {
                // message logging is not support in PT, write the trace
                MessageLogger.inPartialTrust = true;
                if (DiagnosticUtility.ShouldTraceWarning)
                {
                    TraceUtility.TraceEvent(TraceEventType.Warning,
                        TraceCode.TraceHandledException,
                        SR.GetString(SR.PartialTrustMessageLoggingNotEnabled),
                        null,
                        securityException);
                }
                // also write to event log
                LogNonFatalInitializationException(
                    new SecurityException(
                        SR.GetString(SR.PartialTrustMessageLoggingNotEnabled),
                        securityException));
            }
            catch (Exception e)
            {
                MessageLogger.messageTraceSource = null;

                if (Fx.IsFatal(e)) throw;

                LogNonFatalInitializationException(e);
            }
        }
 private static void ExitOrUnloadEventHandler(object sender, EventArgs e)
 {
     lock (syncObject)
     {
         if (MessageTraceSource != null)
         {
             MessageTraceSource.Close();
             messageTraceSource = null;
         }
     }
 }
 private static void InitializeMessageTraceSource()
 {
     try
     {
         attemptedTraceSourceInitialization = true;
         PiiTraceSource source = new PiiTraceSource("System.ServiceModel.MessageLogging", "System.ServiceModel 4.0.0.0") {
             Switch = { Level = SourceLevels.Information }
         };
         source.Listeners.Remove("Default");
         if (source.Listeners.Count > 0)
         {
             AppDomain.CurrentDomain.DomainUnload += new EventHandler(MessageLogger.ExitOrUnloadEventHandler);
             AppDomain.CurrentDomain.ProcessExit += new EventHandler(MessageLogger.ExitOrUnloadEventHandler);
             AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MessageLogger.ExitOrUnloadEventHandler);
         }
         else
         {
             source = null;
         }
         messageTraceSource = source;
     }
     catch (ConfigurationErrorsException)
     {
         throw;
     }
     catch (SecurityException exception)
     {
         inPartialTrust = true;
         if (DiagnosticUtility.ShouldTraceWarning)
         {
             TraceUtility.TraceEvent(TraceEventType.Warning, 0x20004, System.ServiceModel.SR.GetString("PartialTrustMessageLoggingNotEnabled"), null, exception);
         }
         LogNonFatalInitializationException(new SecurityException(System.ServiceModel.SR.GetString("PartialTrustMessageLoggingNotEnabled"), exception));
     }
     catch (Exception exception2)
     {
         messageTraceSource = null;
         if (Fx.IsFatal(exception2))
         {
             throw;
         }
         LogNonFatalInitializationException(exception2);
     }
 }
 private void UnsafeRemoveDefaultTraceListener(PiiTraceSource piiTraceSource)
 {
     piiTraceSource.Listeners.Remove("Default");
 }
 private void CreateTraceSource()
 {
     PiiTraceSource piiTraceSource = null;
     if (this.traceSourceType == TraceSourceKind.PiiTraceSource)
     {
         piiTraceSource = new PiiTraceSource(this.TraceSourceName, this.eventSourceName, SourceLevels.Off);
     }
     else
     {
         piiTraceSource = new System.ServiceModel.Diagnostics.DiagnosticTraceSource(this.TraceSourceName, this.eventSourceName, SourceLevels.Off);
     }
     this.UnsafeRemoveDefaultTraceListener(piiTraceSource);
     this.TraceSource = piiTraceSource;
 }