/// <summary>
        /// Represents a thrown exception and some context.
        /// </summary>
        /// <param name="ex">The exception that was thrown.</param>
        /// <param name="isHandled">Whether the exception is explicitly handled or not.</param>
        /// <param name="correlationID">A unique identifier to tie two or more exception reports together.</param>
        /// <param name="webHostingContext">The current web application hosting context, if applicable.</param>
        /// <param name="capturedHttpContext">Captured values from the current HTTP context being handled, if applicable.</param>
        public ExceptionWithCapturedContext(
            Exception ex,
            bool isHandled = false,
            Guid? correlationID = null,
            WebHostingContext webHostingContext = null,
            CapturedHttpContext capturedHttpContext = null
            )
        {
            // Check for a WrappedException to pull out custom Exception info:
            WrappedException wex = ex as WrappedException;
            Exception thrownEx = ex;
            if (wex != null)
            {
                UserState = wex.UserState;
                ex = wex.Wrapped;
            }

            Exception = ex;

            IsHandled = isHandled;
            CorrelationID = correlationID;
            WebHostingContext = webHostingContext;
            CapturedHttpContext = capturedHttpContext;

            RealStackTrace = new StackTrace(thrownEx, true);

            LoggedTimeUTC = DateTime.UtcNow;
            ManagedThreadID = Thread.CurrentThread.ManagedThreadId;
            SequenceNumber = Interlocked.Increment(ref runningSequenceNumber);

            // Capture some details about the exception:
            var exType = ex.GetType();
            AssemblyName = exType.Assembly.FullName;
            TypeName = exType.FullName;
            // TODO(jsd): Sanitize embedded file paths in stack trace
            StackTrace = thrownEx.StackTrace;

            // SHA1 hash the `assemblyName:typeName:stackTrace[:targetSite]`:
            string hashableData = String.Concat(AssemblyName, ":", TypeName, ":", StackTrace);

            if (RealStackTrace != null && RealStackTrace.FrameCount > 0)
            {
                // Add in TargetSite data:
                TargetSite = new ExceptionTargetSite(RealStackTrace);
                hashableData += ":" + TargetSite.GetHashableData();
            }

            ExceptionID = Hash.SHA1(hashableData);

            if (ex.InnerException != null)
                InnerException = new ExceptionWithCapturedContext(ex.InnerException, isHandled, correlationID, webHostingContext, capturedHttpContext);
        }
Exemplo n.º 2
0
 static SHA1Hash CalcWebApplicationID(WebHostingContext host)
 {
     var id = Hash.SHA1(
         String.Concat(
             host.MachineName, ":",
             host.ApplicationID, ":",
             host.PhysicalPath, ":",
             host.VirtualPath, ":",
             host.SiteName
         )
     );
     return id;
 }