Exemple #1
0
        /// <summary>
        /// Initialises a new instance of the FieldLogExceptionItem class.
        /// </summary>
        /// <param name="priority">The priority of the new log item.</param>
        /// <param name="type">The scope type.</param>
        /// <param name="name">The scope name.</param>
        /// <param name="webRequestData">The web request data. This parameter is required for the WebRequestStart scope type.</param>
        public FieldLogScopeItem(FieldLogPriority priority, FieldLogScopeType type, string name, FieldLogWebRequestData webRequestData)
            : base(priority)
        {
            Type  = type;
            Level = FL.ScopeLevel;
            Name  = name;

            if (Type == FieldLogScopeType.ThreadStart)
            {
                IsBackgroundThread = Thread.CurrentThread.IsBackground;
                IsPoolThread       = Thread.CurrentThread.IsThreadPoolThread;

                Thread = Thread.CurrentThread;
            }
            if (Type == FieldLogScopeType.LogStart)
            {
                EnvironmentData = FieldLogEventEnvironment.Current();
                Size           += EnvironmentData.Size;
            }
            if (Type == FieldLogScopeType.WebRequestStart)
            {
                if (webRequestData == null)
                {
                    throw new ArgumentNullException("webRequestData", "The webRequestData parameter is required for the WebRequestStart scope type.");
                }
                WebRequestData = webRequestData;
                Size          += WebRequestData.Size;
            }

            Size += 4 + 4 +
                    (Name != null ? Name.Length * 2 : 0) +
                    4 + 4 + 4 + 4 + 4;
        }
Exemple #2
0
        /// <summary>
        /// Initialises a new instance of the FieldLogExceptionItem class.
        /// </summary>
        /// <param name="priority">The priority of the new log item.</param>
        /// <param name="ex">The exception instance.</param>
        /// <param name="context">The context in which the exception has been thrown. Can be an
        /// arbitrary string that is useful for the logging purpose.</param>
        /// <param name="customStackTrace">A StackTrace that shall be logged instead of the StackTrace from the Exception instance.</param>
        public FieldLogExceptionItem(FieldLogPriority priority, Exception ex, string context, StackTrace customStackTrace)
            : base(priority)
        {
            Exception = new FieldLogException(ex, customStackTrace);
            Context   = context;

            bool includeEnvironment = true;

            if (context == "AppDomain.FirstChanceException" ||
                context == FL.StackTraceOnlyExceptionContext)
            {
                // First-chance exception logging with environment may lead to crashes at WMI
                // requests, so it's disabled for now.
                // Testcase: Inspect FieldLogViewer with Snoop while debugging.
                includeEnvironment = false;
            }
            if (includeEnvironment)
            {
                EnvironmentData = FieldLogEventEnvironment.Current();
            }
            else
            {
                EnvironmentData = FieldLogEventEnvironment.Empty;
            }

            Size += Exception.Size +
                    (Context != null ? Context.Length * 2 : 0) +
                    EnvironmentData.Size;
        }