public override void TraceEventLogEvent(TraceEventType type, TraceRecord traceRecord)
 {
     TraceEvent(type,
                DiagnosticsTraceCode.EventLog, LegacyDiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "EventLog"),
                TraceSR.GetString(TraceSR.TraceCodeEventLog),
                traceRecord, null, null);
 }
        private void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
        {
            Exception exceptionObject = (Exception)args.ExceptionObject;

            this.TraceEvent(TraceEventType.Critical, 0x20005, "UnhandledException", TraceSR.GetString("UnhandledException"), null, exceptionObject, null);
            this.ShutdownTracing();
        }
 private static TraceSR GetLoader()
 {
     if (loader == null)
     {
         TraceSR esr = new TraceSR();
         Interlocked.CompareExchange <TraceSR>(ref loader, esr, null);
     }
     return(loader);
 }
 private static TraceSR GetLoader()
 {
     if (loader == null)
     {
         TraceSR esr = new TraceSR();
         Interlocked.CompareExchange<TraceSR>(ref loader, esr, null);
     }
     return loader;
 }
        public static string GetString(string name)
        {
            TraceSR loader = GetLoader();

            if (loader == null)
            {
                return(null);
            }
            return(loader.resources.GetString(name, Culture));
        }
Exemplo n.º 6
0
 public override void WriteChars(char[] buffer, int index, int count)
 {
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     if (index < 0)
     {
         throw new ArgumentOutOfRangeException("index");
     }
     if (count < 0)
     {
         throw new ArgumentOutOfRangeException("count");
     }
     if ((buffer.Length - index) < count)
     {
         throw new ArgumentException(TraceSR.GetString("WriteCharsInvalidContent"));
     }
     this.WriteString(new string(buffer, index, count));
 }
 public override void WriteChars(Char[] buffer, int index, int count)
 {
     // Exceptions being thrown as per data found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemxmlxmlwriterclasswritecharstopic.asp
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     if (index < 0)
     {
         throw new ArgumentOutOfRangeException("index");
     }
     if (count < 0)
     {
         throw new ArgumentOutOfRangeException("count");
     }
     if ((buffer.Length - index) < count)
     {
         throw new ArgumentException(TraceSR.GetString(TraceSR.WriteCharsInvalidContent));
     }
     this.WriteString(new string(buffer, index, count));
 }
        public static string GetString(string name, params object[] args)
        {
            TraceSR loader = GetLoader();

            if (loader == null)
            {
                return(null);
            }
            string format = loader.resources.GetString(name, Culture);

            if ((args == null) || (args.Length <= 0))
            {
                return(format);
            }
            for (int i = 0; i < args.Length; i++)
            {
                string str2 = args[i] as string;
                if ((str2 != null) && (str2.Length > 0x400))
                {
                    args[i] = str2.Substring(0, 0x3fd) + "...";
                }
            }
            return(string.Format(CultureInfo.CurrentCulture, format, args));
        }
#pragma warning disable 56500
        internal void TraceEvent(TraceEventType type, int code, string msdnTraceCode, string description, TraceRecord trace, Exception exception, object source)
        {
#pragma warning disable 618
            Fx.Assert(exception == null || type <= TraceEventType.Information, "Exceptions should be traced at Information or higher");
            Fx.Assert(!string.IsNullOrEmpty(description), "All TraceCodes should have a description");
#pragma warning restore 618
            TraceXPathNavigator navigator = null;
            try
            {
#pragma warning disable 618
                if (this.TraceSource != null && this.HaveListeners)
#pragma warning restore 618
                {
                    try
                    {
                        BuildTrace(type, msdnTraceCode, description, trace, exception, source, out navigator);
                    }
                    catch (PlainXmlWriter.MaxSizeExceededException)
                    {
                        StringTraceRecord codeTraceRecord = new StringTraceRecord("TruncatedTraceId", msdnTraceCode);
                        this.TraceEvent(type, DiagnosticsTraceCode.TraceTruncatedQuotaExceeded, LegacyDiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "TraceTruncatedQuotaExceeded"), TraceSR.GetString(TraceSR.TraceCodeTraceTruncatedQuotaExceeded), codeTraceRecord, null, null);
                    }
                    this.TraceSource.TraceData(type, code, navigator);
                    if (this.CalledShutdown)
                    {
                        this.TraceSource.Flush();
                    }
                    // Must have been a successful trace.
                    this.LastFailure = DateTime.MinValue;
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                LogTraceFailure(navigator == null ? string.Empty : navigator.ToString(), e);
            }
        }
        internal void TraceEvent(TraceEventType type, int code, string msdnTraceCode, string description, TraceRecord trace, Exception exception, object source)
        {
            TraceXPathNavigator navigator = null;

            try
            {
                if ((this.TraceSource != null) && this.HaveListeners)
                {
                    try
                    {
                        this.BuildTrace(type, msdnTraceCode, description, trace, exception, source, out navigator);
                    }
                    catch (PlainXmlWriter.MaxSizeExceededException)
                    {
                        StringTraceRecord record = new StringTraceRecord("TruncatedTraceId", msdnTraceCode);
                        this.TraceEvent(type, 0x2000c, GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "TraceTruncatedQuotaExceeded"), TraceSR.GetString("TraceCodeTraceTruncatedQuotaExceeded"), record, null, null);
                    }
                    this.TraceSource.TraceData(type, code, navigator);
                    if (this.calledShutdown)
                    {
                        this.TraceSource.Flush();
                    }
                    this.LastFailure = DateTime.MinValue;
                }
            }
            catch (Exception exception2)
            {
                if (Fx.IsFatal(exception2))
                {
                    throw;
                }
                this.LogTraceFailure((navigator == null) ? string.Empty : navigator.ToString(), exception2);
            }
        }
 private void ShutdownTracing()
 {
     if ((this.TraceSource != null) && !this.calledShutdown)
     {
         try
         {
             if (this.Level != SourceLevels.Off)
             {
                 if (this.ShouldTrace(TraceEventType.Information))
                 {
                     Dictionary <string, string> dictionary = new Dictionary <string, string>(3);
                     dictionary["AppDomain.FriendlyName"] = AppDomain.CurrentDomain.FriendlyName;
                     dictionary["ProcessName"]            = ProcessName;
                     dictionary["ProcessId"] = ProcessId.ToString(CultureInfo.CurrentCulture);
                     this.TraceEvent(TraceEventType.Information, 0x20001, GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "AppDomainUnload"), TraceSR.GetString("TraceCodeAppDomainUnload"), new DictionaryTraceRecord(dictionary), null, null);
                 }
                 this.calledShutdown = true;
                 this.TraceSource.Flush();
             }
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             this.LogTraceFailure(null, exception);
         }
     }
 }
 protected override string GetLocalizedString(string value)
 {
     return(TraceSR.GetString(value));
 }
Exemplo n.º 13
0
 internal void LogEvent(TraceEventType type, EventLogCategory category, System.ServiceModel.Diagnostics.EventLogEventId eventId, bool shouldTrace, params string[] values)
 {
     if (canLogEvent)
     {
         try
         {
             this.SafeLogEvent(type, category, eventId, shouldTrace, values);
         }
         catch (SecurityException exception)
         {
             canLogEvent = false;
             if (shouldTrace && (this.diagnosticTrace != null))
             {
                 this.diagnosticTrace.TraceEvent(TraceEventType.Warning, 0x20004, System.ServiceModel.Diagnostics.DiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "TraceHandledException"), TraceSR.GetString("TraceHandledException"), null, exception, null);
             }
         }
     }
 }
Exemplo n.º 14
0
 internal void UnsafeLogEvent(TraceEventType type, EventLogCategory category, System.ServiceModel.Diagnostics.EventLogEventId eventId, bool shouldTrace, params string[] values)
 {
     if (logCountForPT < 5)
     {
         try
         {
             int      num       = 0;
             string[] logValues = new string[values.Length + 2];
             for (int i = 0; i < values.Length; i++)
             {
                 string str = values[i];
                 if (!string.IsNullOrEmpty(str))
                 {
                     str = NormalizeEventLogParameter(str);
                 }
                 else
                 {
                     str = string.Empty;
                 }
                 logValues[i] = str;
                 num         += str.Length + 1;
             }
             string str2 = NormalizeEventLogParameter(this.UnsafeGetProcessName());
             logValues[logValues.Length - 2] = str2;
             num += str2.Length + 1;
             string str3 = this.UnsafeGetProcessId().ToString(CultureInfo.InvariantCulture);
             logValues[logValues.Length - 1] = str3;
             num += str3.Length + 1;
             if (num > 0x6400)
             {
                 int length = (0x6400 / logValues.Length) - 1;
                 for (int j = 0; j < logValues.Length; j++)
                 {
                     if (logValues[j].Length > length)
                     {
                         logValues[j] = logValues[j].Substring(0, length);
                     }
                 }
             }
             SecurityIdentifier user       = WindowsIdentity.GetCurrent().User;
             byte[]             binaryForm = new byte[user.BinaryLength];
             user.GetBinaryForm(binaryForm, 0);
             IntPtr[]   ptrArray          = new IntPtr[logValues.Length];
             GCHandle   stringsRootHandle = new GCHandle();
             GCHandle[] handleArray       = null;
             try
             {
                 stringsRootHandle = GCHandle.Alloc(ptrArray, GCHandleType.Pinned);
                 handleArray       = new GCHandle[logValues.Length];
                 for (int k = 0; k < logValues.Length; k++)
                 {
                     handleArray[k] = GCHandle.Alloc(logValues[k], GCHandleType.Pinned);
                     ptrArray[k]    = handleArray[k].AddrOfPinnedObject();
                 }
                 this.UnsafeWriteEventLog(type, category, eventId, logValues, binaryForm, stringsRootHandle);
             }
             finally
             {
                 if (stringsRootHandle.AddrOfPinnedObject() != IntPtr.Zero)
                 {
                     stringsRootHandle.Free();
                 }
                 if (handleArray != null)
                 {
                     foreach (GCHandle handle2 in handleArray)
                     {
                         handle2.Free();
                     }
                 }
             }
             if (shouldTrace && (this.diagnosticTrace != null))
             {
                 Dictionary <string, string> dictionary = new Dictionary <string, string>(logValues.Length + 4);
                 dictionary["CategoryID.Name"]  = category.ToString();
                 dictionary["CategoryID.Value"] = ((uint)category).ToString(CultureInfo.InvariantCulture);
                 dictionary["InstanceID.Name"]  = eventId.ToString();
                 dictionary["InstanceID.Value"] = ((uint)eventId).ToString(CultureInfo.InvariantCulture);
                 for (int m = 0; m < values.Length; m++)
                 {
                     dictionary.Add("Value" + m.ToString(CultureInfo.InvariantCulture), (values[m] == null) ? string.Empty : System.Runtime.Diagnostics.DiagnosticTrace.XmlEncode(values[m]));
                 }
                 this.diagnosticTrace.TraceEvent(type, 0x20002, System.ServiceModel.Diagnostics.DiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "EventLog"), TraceSR.GetString("TraceCodeEventLog"), new DictionaryTraceRecord(dictionary), null, null);
             }
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
         }
         if (this.isInPatialTrust)
         {
             logCountForPT++;
         }
     }
 }
 protected override void OnUnhandledException(Exception exception)
 {
     TraceEvent(TraceEventType.Critical, DiagnosticsTraceCode.UnhandledException, "UnhandledException", TraceSR.GetString(TraceSR.UnhandledException), null, exception, null);
 }
 internal void TraceHandledException(Exception exception, TraceEventType eventType)
 {
     if ((this.diagnosticTrace != null) && this.diagnosticTrace.ShouldTrace(eventType))
     {
         using (useStaticActivityId ? Activity.CreateActivity(activityId) : null)
         {
             this.diagnosticTrace.TraceEvent(eventType, 0x20004, System.ServiceModel.Diagnostics.DiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "TraceHandledException"), TraceSR.GetString("TraceHandledException"), null, exception, null);
         }
     }
 }
        protected override void OnShutdownTracing()
        {
            if (null != this.TraceSource)
            {
#pragma warning disable 618
                if (this.Level != SourceLevels.Off)
                {
                    if (this.ShouldTrace(TraceEventType.Information))
#pragma warning restore 618
                    {
                        Dictionary <string, string> values = new Dictionary <string, string>(3);
                        values["AppDomain.FriendlyName"] = AppDomain.CurrentDomain.FriendlyName;
                        values["ProcessName"]            = DiagnosticTraceBase.ProcessName;
                        values["ProcessId"] = DiagnosticTraceBase.ProcessId.ToString(CultureInfo.CurrentCulture);
                        this.TraceEvent(TraceEventType.Information, DiagnosticsTraceCode.AppDomainUnload, LegacyDiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "AppDomainUnload"), TraceSR.GetString(TraceSR.TraceCodeAppDomainUnload),
                                        new DictionaryTraceRecord(values), null, null);
                    }
                    this.TraceSource.Flush();
                }
            }
        }
Exemplo n.º 18
0
        internal void DiagnosticTraceHandledException(Exception exception, TraceEventType eventType)
        {
#pragma warning disable 618
            bool shouldTrace = (this.diagnosticTrace != null && this.diagnosticTrace.ShouldTrace(eventType));
#pragma warning restore 618
            if (shouldTrace)
            {
                using (ExceptionUtility.useStaticActivityId ? Activity.CreateActivity(ExceptionUtility.activityId) : null)
                {
                    this.diagnosticTrace.TraceEvent(eventType, DiagnosticsTraceCode.TraceHandledException, LegacyDiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "TraceHandledException"), TraceSR.GetString(TraceSR.TraceHandledException), null, exception, null);
                }
            }
        }
Exemplo n.º 19
0
 internal Exception ThrowHelperCallback(Exception innerException)
 {
     return(this.ThrowHelperCallback(TraceSR.GetString(TraceSR.GenericCallbackException), innerException));
 }
Exemplo n.º 20
0
 internal ArgumentException ThrowHelperArgumentNullOrEmptyString(string arg)
 {
     return((ArgumentException)this.ThrowHelperError(new ArgumentException(TraceSR.GetString(TraceSR.StringNullOrEmpty), arg)));
 }
Exemplo n.º 21
0
        internal Exception ThrowHelper(Exception exception, TraceEventType eventType, TraceRecord extendedData)
        {
#pragma warning disable 618
            bool shouldTrace = (this.diagnosticTrace != null && this.diagnosticTrace.ShouldTrace(eventType));
#pragma warning restore 618
            if (shouldTrace)
            {
                using (ExceptionUtility.useStaticActivityId ? Activity.CreateActivity(ExceptionUtility.activityId) : null)
                {
                    this.diagnosticTrace.TraceEvent(eventType, DiagnosticsTraceCode.ThrowingException, LegacyDiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "ThrowingException"), TraceSR.GetString(TraceSR.ThrowingException), extendedData, exception, null);
                }

                IDictionary data = exception.Data;
                if (data != null && !data.IsReadOnly && !data.IsFixedSize)
                {
                    object existingString = data[ExceptionStackAsStringKey];
                    string stackString    = existingString == null ? "" : existingString as string;
                    if (stackString != null)
                    {
                        string stack = exception.StackTrace;
                        if (!string.IsNullOrEmpty(stack))
                        {
                            stackString = string.Concat(stackString, stackString.Length == 0 ? "" : Environment.NewLine, "throw", Environment.NewLine, stack, Environment.NewLine, "catch", Environment.NewLine);
                            data[ExceptionStackAsStringKey] = stackString;
                        }
                    }
                }
            }

            // Trace using ETW as well.
            exceptionTrace.TraceEtwException(exception, eventType);

            return(exception);
        }
        internal Exception ThrowHelper(Exception exception, TraceEventType eventType, TraceRecord extendedData)
        {
            bool flag = (this.diagnosticTrace != null) && this.diagnosticTrace.ShouldTrace(eventType);

            if (flag)
            {
                using (useStaticActivityId ? Activity.CreateActivity(activityId) : null)
                {
                    this.diagnosticTrace.TraceEvent(eventType, 0x20003, System.ServiceModel.Diagnostics.DiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics", "ThrowingException"), TraceSR.GetString("ThrowingException"), extendedData, exception, null);
                }
            }
            string str = flag ? exception.StackTrace : null;

            if (!string.IsNullOrEmpty(str))
            {
                IDictionary data = exception.Data;
                if (((data != null) && !data.IsReadOnly) && !data.IsFixedSize)
                {
                    object obj2 = data["System.ServiceModel.Diagnostics.ExceptionUtility.ExceptionStackAsString"];
                    string str2 = (obj2 == null) ? "" : (obj2 as string);
                    if (str2 != null)
                    {
                        str2 = str2 + ((str2.Length == 0) ? "" : Environment.NewLine) + "throw" + Environment.NewLine + str + Environment.NewLine + "catch" + Environment.NewLine;
                        data["System.ServiceModel.Diagnostics.ExceptionUtility.ExceptionStackAsString"] = str2;
                    }
                }
            }
            return(exception);
        }