Пример #1
0
        public void Process(Exception exception, SentryEvent sentryEvent)
        {
            if ((bool)exception.Data["TickException"])
            {
                return;
            }

            // create folder "crashes"
            var crashes = Path.Combine(AppContext.BaseDirectory, "Crashes");

            Directory.CreateDirectory(crashes);

            // open filestream to write minidump to crashes folder
            var file = new FileStream(Path.Combine(crashes, $"{Guid.NewGuid()}.dmp"), FileMode.Create);
            var info = new MINIDUMP_EXCEPTION_INFORMATION
            {
                ThreadId          = GetCurrentThreadId(),
                ExceptionPointers = Marshal.GetExceptionPointers(),
                ClientPointers    = 1
            };

            MiniDumpWriteDump(
                GetCurrentProcess(),
                GetCurrentProcessId(),
                file.SafeFileHandle.DangerousGetHandle(),
                (int)MINIDUMP_TYPE.MiniDumpWithFullMemory,
                ref info,
                IntPtr.Zero,
                IntPtr.Zero);

            file.Close();

            // inform the user a minidump has been written
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("A minidump has been written to " + file.Name + ", please send this file to the developers.");
            Console.ResetColor();

            sentryEvent.SetExtra("minidump", Path.GetFileName(file.Name));
        }