示例#1
0
        static internal void TraceAndLogEvent(TraceEventType type, string code, string description, TraceRecord trace, Exception exception, ref Guid activityId, object source)
        {
            bool   shouldTrace = DiagnosticTrace.ShouldTrace(type);
            string traceString = null;

            try
            {
                LogEvent(type, code, description, trace, exception, source);

                if (shouldTrace)
                {
                    DiagnosticTrace.TraceEvent(type, code, description, trace, exception, ref activityId, false, source);
                }
            }
            catch (OutOfMemoryException)
            {
                throw;
            }
            catch (StackOverflowException)
            {
                throw;
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (Exception e)
            {
                LogTraceFailure(traceString, e);
            }
        }
示例#2
0
        static void SetLevel(SourceLevels level)
        {
            SourceLevels fixedLevel = FixLevel(level);

            DiagnosticTrace.level = fixedLevel;
            if (DiagnosticTrace.TraceSource != null)
            {
                DiagnosticTrace.TraceSource.Switch.Level = fixedLevel;
                DiagnosticTrace.shouldCorrelate          = DiagnosticTrace.ShouldTrace(TraceEventType.Transfer);
                DiagnosticTrace.shouldTraceVerbose       = DiagnosticTrace.ShouldTrace(TraceEventType.Verbose);
                DiagnosticTrace.shouldTraceInformation   = DiagnosticTrace.ShouldTrace(TraceEventType.Information);
                DiagnosticTrace.shouldTraceWarning       = DiagnosticTrace.ShouldTrace(TraceEventType.Warning);
                DiagnosticTrace.shouldTraceError         = DiagnosticTrace.ShouldTrace(TraceEventType.Error);
                DiagnosticTrace.shouldTraceCritical      = DiagnosticTrace.ShouldTrace(TraceEventType.Critical);
            }
        }
示例#3
0
        static internal void TraceEvent(TraceEventType type, string code, string description, TraceRecord trace, Exception exception, ref Guid activityId, bool emitTransfer, object source)
        {
#if DEBUG
            Debug.Assert(exception == null || type <= TraceEventType.Information);
            Debug.Assert(!string.IsNullOrEmpty(description), "All TraceCodes should have a description");
#endif
            if (DiagnosticTrace.ShouldTrace(type))
            {
                using (Activity.CreateActivity(activityId, emitTransfer))
                {
                    XPathNavigator navigator = BuildTraceString(type, code, description, trace, exception, source);
                    try
                    {
                        DiagnosticTrace.TraceSource.TraceData(type, 0, navigator);
                        if (DiagnosticTrace.calledShutdown)
                        {
                            DiagnosticTrace.TraceSource.Flush();
                        }
                    }
                    catch (OutOfMemoryException)
                    {
                        throw;
                    }
                    catch (StackOverflowException)
                    {
                        throw;
                    }
                    catch (ThreadAbortException)
                    {
                        throw;
                    }
                    catch (Exception e)
                    {
                        string traceString = SR.GetString(SR.TraceFailure,
                                                          type.ToString(),
                                                          code,
                                                          description,
                                                          source == null ? string.Empty : DiagnosticTrace.CreateSourceString(source));
                        LogTraceFailure(traceString, e);
                    }
                }
            }
        }