コード例 #1
0
        protected override bool Initialize(Assembly assembly)
        {
            Type type = assembly.GetType("System.Net.Logging");

            if (type == null)
            {
                string failure = "type 'System.Net.Logging' not found in assembly '" + assembly.FullName + "'";
                SystemNetLogging.ReportFailure(1, failure);
                SystemNetLogging.ReportFailure(0, failure);
                return(false);
            }
            this.fieldEnabled = type.GetTypeInfo().GetDeclaredField("s_LoggingEnabled");
            if (this.fieldEnabled == null || this.fieldEnabled.IsPublic || !this.fieldEnabled.IsStatic)
            {
                string failure2 = "static field 's_LoggingEnabled' not found in type 'System.Net.Logging'";
                SystemNetLogging.ReportFailure(1, failure2);
                SystemNetLogging.ReportFailure(0, failure2);
                return(false);
            }
            SystemTrace.SetFieldValue(this.fieldEnabled, false);
            PropertyInfo declaredProperty = type.GetTypeInfo().GetDeclaredProperty("On");

            if (declaredProperty == null)
            {
                string failure3 = "static property 'On' not found in 'System.Net.Logging' type";
                SystemNetLogging.ReportFailure(1, failure3);
                SystemNetLogging.ReportFailure(0, failure3);
                return(false);
            }
            declaredProperty.GetValue(null, null);
            this.socketsSource      = SystemNetLogging.GetTraceSource(1, "s_SocketsTraceSource", type);
            this.webSource          = SystemNetLogging.GetTraceSource(0, "s_WebTraceSource", type);
            this.httpListenerSource = SystemNetLogging.GetTraceSource(2, "s_HttpListenerTraceSource", type);
            return(this.webSource != null || this.socketsSource != null || this.httpListenerSource != null);
        }
コード例 #2
0
 private void AssemblyLoadHandler(object sender, AssemblyLoadEventArgs args)
 {
     if (SystemTrace.IsMatchingAssemblyName(args.LoadedAssembly, this.assemblyName))
     {
         AppDomain.CurrentDomain.AssemblyLoad -= this.AssemblyLoadHandler;
         this.SafeInitialize(args.LoadedAssembly);
         this.Update();
     }
 }
コード例 #3
0
        protected override void Update()
        {
            bool flag = this.Enabled && (this.logMalformedMessages || this.logMessagesAtServiceLevel || this.logMessagesAtTransportLevel || this.logMessageBody);

            base.ConnectListener(this.source, this.listener, flag);
            this.source.Switch.Level = (flag ? base.SourceLevels : SourceLevels.Off);
            SystemTrace.SetPropertyValue(this.propertyLogMalformedMessages, this.logMalformedMessages);
            SystemTrace.SetPropertyValue(this.propertyLogMessagesAtServiceLevel, this.logMessagesAtServiceLevel);
            SystemTrace.SetPropertyValue(this.propertyLogMessagesAtTransportLevel, this.logMessagesAtTransportLevel);
            SystemTrace.SetPropertyValue(this.propertyLogMessageBody, this.logMessageBody);
        }
コード例 #4
0
 protected static Assembly GetAssembly(string assemblyName)
 {
     Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
     if (assemblies != null)
     {
         foreach (Assembly assembly in assemblies)
         {
             if (SystemTrace.IsMatchingAssemblyName(assembly, assemblyName))
             {
                 return(assembly);
             }
         }
     }
     return(null);
 }
コード例 #5
0
        protected override void Update()
        {
            bool flag = this.httpListenerExtendedErrorListener != null;

            SystemTrace.SetFieldValue(this.fieldEnabled, flag || this.enabled);
            SourceLevels sourceLevels = this.enabled ? base.SourceLevels : SourceLevels.Off;

            this.socketsSource.Switch.Level      = sourceLevels;
            this.webSource.Switch.Level          = sourceLevels;
            this.httpListenerSource.Switch.Level = ((flag && (sourceLevels == SourceLevels.Off || sourceLevels == SourceLevels.Critical)) ? SourceLevels.Error : sourceLevels);
            base.ConnectListener(this.socketsSource, this.socketsListener, this.enabled);
            base.ConnectListener(this.webSource, this.webListener, this.enabled);
            base.ConnectListener(this.httpListenerSource, this.httpListenerListener, this.enabled);
            if (flag)
            {
                base.ConnectListener(this.httpListenerSource, this.httpListenerExtendedErrorListener, true);
            }
        }
コード例 #6
0
 private Assembly GetAssembly()
 {
     return(SystemTrace.GetAssembly(this.assemblyName));
 }
コード例 #7
0
        protected override bool Initialize(Assembly assembly)
        {
            Type type = assembly.GetType("System.ServiceModel.Diagnostics.MessageLogger");

            if (type == null)
            {
                SystemServiceModelMessageLogging.ReportFailure("type 'System.ServiceModel.Diagnostics.MessageLogger' not found in assembly " + assembly.FullName);
                return(false);
            }
            FieldInfo declaredField = type.GetTypeInfo().GetDeclaredField("messageTraceSource");

            if (declaredField == null || declaredField.IsPublic || !declaredField.IsStatic)
            {
                SystemServiceModelMessageLogging.ReportFailure("field 'messageTraceSource' not found in type " + type.Name);
                return(false);
            }
            Assembly assembly2 = SystemTrace.GetAssembly("SMDiagnostics");

            if (assembly2 == null)
            {
                SystemServiceModelMessageLogging.ReportFailure("assembly 'SMDiagnostics' not found");
                return(false);
            }
            Type type2 = assembly2.GetType("System.ServiceModel.Diagnostics.PiiTraceSource");

            if (type2 == null)
            {
                SystemServiceModelMessageLogging.ReportFailure("type 'System.ServiceModel.Diagnostics.PiiTraceSource' not found in assembly " + assembly2.FullName);
                return(false);
            }
            ConstructorInfo constructorInfo = null;

            foreach (ConstructorInfo constructorInfo2 in type2.GetTypeInfo().DeclaredConstructors)
            {
                if (!constructorInfo2.IsPublic)
                {
                    ParameterInfo[] parameters = constructorInfo2.GetParameters();
                    if (parameters != null && parameters.Length == 2 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(string))
                    {
                        constructorInfo = constructorInfo2;
                        break;
                    }
                }
            }
            if (constructorInfo == null)
            {
                SystemServiceModelMessageLogging.ReportFailure("instance constructor 'System.ServiceModel.Diagnostics.PiiTraceSource(string,string)' not found");
                return(false);
            }
            object obj = constructorInfo.Invoke(new object[]
            {
                "System.ServiceModel.MessageLogging",
                "System.ServiceModel 4.0.0.0"
            });

            this.source = (obj as TraceSource);
            if (this.source == null)
            {
                SystemServiceModelMessageLogging.ReportFailure("instance constructor 'System.ServiceModel.Diagnostics.PiiTraceSource(string,string)' did not return TraceSource object");
                return(false);
            }
            this.source.Switch.Level = SourceLevels.Off;
            this.source.Listeners.Remove("Default");
            declaredField.SetValue(null, this.source);
            TypeInfo typeInfo = type.GetTypeInfo();

            this.propertyLogMalformedMessages        = typeInfo.GetDeclaredProperty("LogMalformedMessages");
            this.propertyLogMessagesAtServiceLevel   = typeInfo.GetDeclaredProperty("LogMessagesAtServiceLevel");
            this.propertyLogMessagesAtTransportLevel = typeInfo.GetDeclaredProperty("LogMessagesAtTransportLevel");
            this.propertyLogMessageBody = typeInfo.GetDeclaredProperty("LogMessageBody");
            SystemServiceModelMessageLogging.SetMinimum(type, "MaxMessageSize", 262144);
            SystemServiceModelMessageLogging.SetMinimum(type, "MaxNumberOfMessagesToLog", 10000);
            return(true);
        }