Beispiel #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);
        }
Beispiel #2
0
        private static TraceSource GetTraceSource(int traceTag, string fieldName, Type type)
        {
            FieldInfo declaredField = type.GetTypeInfo().GetDeclaredField(fieldName);

            if (declaredField == null || declaredField.IsPublic || !declaredField.IsStatic)
            {
                SystemNetLogging.ReportFailure(traceTag, string.Concat(new string[]
                {
                    "static field '",
                    fieldName,
                    "' not found in '",
                    type.Name,
                    "' type"
                }));
                return(null);
            }
            TraceSource traceSource = declaredField.GetValue(null) as TraceSource;

            if (traceSource == null)
            {
                SystemNetLogging.ReportFailure(traceTag, "static field '" + fieldName + "' does not contain object of 'TraceSource' type");
                return(null);
            }
            traceSource.Listeners.Remove("Default");
            traceSource.Switch.Level = SourceLevels.Off;
            traceSource.SetMaxDataSize(1073741824);
            return(traceSource);
        }