예제 #1
0
        private static void DumpThreadAborts(global::Serilog.ILogger logger, LogEventLevel level, Exception exception, ref string messageTemplate)
        {
            var dump = false;

            if (IsTimeoutThreadAbortException(exception))
            {
                messageTemplate += "\r\nThe thread has been aborted, because the request has timed out.";

                // dump if configured, or if stacktrace contains Monitor.ReliableEnter
                dump = Current.Configs.CoreDebug().DumpOnTimeoutThreadAbort || IsMonitorEnterThreadAbortException(exception);

                // dump if it is ok to dump (might have a cap on number of dump...)
                dump &= MiniDump.OkToDump();
            }

            if (dump)
            {
                try
                {
                    var dumped = MiniDump.Dump(withException: true);
                    messageTemplate += dumped
                        ? "\r\nA minidump was created in App_Data/MiniDump"
                        : "\r\nFailed to create a minidump";
                }
                catch (Exception ex)
                {
                    messageTemplate += "\r\nFailed to create a minidump";

                    //Log a new entry (as opposed to appending to same log entry)
                    logger.Write(level, ex, "Failed to create a minidump ({ExType}: {ExMessage})",
                                 new object[] { ex.GetType().FullName, ex.Message });
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Dumps the contents of memory to a dumpfile.
 /// </summary>
 /// <param name="dumpFolder">Path to the folder to store the dump file.</param>
 /// <param name="e">The exception which is being handled.</param>
 private void WriteMemoryDump(string dumpFolder, Exception e)
 {
     //Open a file stream
     using (FileStream stream = new FileStream(Path.Combine(dumpFolder, MemoryDumpFileName),
                                               FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
     {
         //Store the exception information
         MiniDump.Dump(stream);
     }
 }
예제 #3
0
        public void Error(Type callingType, string message, Exception exception)
        {
            var logger = LogManager.GetLogger(callingType);

            if (logger == null)
            {
                return;
            }

            var dump = false;

            if (IsTimeoutThreadAbortException(exception))
            {
                message += "\r\nThe thread has been aborted, because the request has timed out.";

                // dump if configured, or if stacktrace contains Monitor.ReliableEnter
                dump = UmbracoConfig.For.CoreDebug().DumpOnTimeoutThreadAbort || IsMonitorEnterThreadAbortException(exception);

                // dump if it is ok to dump (might have a cap on number of dump...)
                dump &= MiniDump.OkToDump();
            }

            if (dump)
            {
                try
                {
                    var dumped = MiniDump.Dump(withException: true);
                    message += dumped
                        ? "\r\nA minidump was created in App_Data/MiniDump"
                        : "\r\nFailed to create a minidump";
                }
                catch (Exception e)
                {
                    message += string.Format("\r\nFailed to create a minidump ({0}: {1})", e.GetType().FullName, e.Message);
                }
            }

            logger.Error(message, exception);
        }
예제 #4
0
    private void DumpThreadAborts(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
    {
        if (!IsTimeoutThreadAbortException(logEvent.Exception))
        {
            return;
        }

        var message = "The thread has been aborted, because the request has timed out.";

        // dump if configured, or if stacktrace contains Monitor.ReliableEnter
        var dump = _coreDebugSettings.DumpOnTimeoutThreadAbort ||
                   IsMonitorEnterThreadAbortException(logEvent.Exception);

        // dump if it is ok to dump (might have a cap on number of dump...)
        dump &= MiniDump.OkToDump(_hostingEnvironment);

        if (!dump)
        {
            message += ". No minidump was created.";
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ThreadAbortExceptionInfo", message));
        }
        else
        {
            try
            {
                var dumped = MiniDump.Dump(_marchal, _hostingEnvironment, withException: true);
                message += dumped
                    ? ". A minidump was created in App_Data/MiniDump."
                    : ". Failed to create a minidump.";
                logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ThreadAbortExceptionInfo", message));
            }
            catch (Exception ex)
            {
                message = "Failed to create a minidump. " + ex;
                logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ThreadAbortExceptionInfo", message));
            }
        }
    }