|
13 | 13 | using System.Windows.Threading; |
14 | 14 | using NLog; |
15 | 15 | using NLog.Targets; |
| 16 | +using Sandbox; |
16 | 17 | using Sandbox.Engine.Utils; |
17 | 18 | using Torch.Utils; |
| 19 | +using VRage; |
18 | 20 | using VRage.FileSystem; |
| 21 | +using VRage.Scripting; |
| 22 | +using VRage.Utils; |
19 | 23 |
|
20 | 24 | namespace Torch.Server |
21 | 25 | { |
@@ -60,6 +64,7 @@ public bool Initialize(string[] args) |
60 | 64 | #endif |
61 | 65 |
|
62 | 66 | #if DEBUG |
| 67 | + AppDomain.CurrentDomain.UnhandledException += HandleException; |
63 | 68 | //enables logging debug messages when built in debug mode. Amazing. |
64 | 69 | LogManager.Configuration.AddRule(LogLevel.Debug, LogLevel.Debug, "main"); |
65 | 70 | LogManager.Configuration.AddRule(LogLevel.Debug, LogLevel.Debug, "console"); |
@@ -255,19 +260,37 @@ private void LogException(Exception ex) |
255 | 260 | } |
256 | 261 | } |
257 | 262 |
|
| 263 | + private void SendAndDump() |
| 264 | + { |
| 265 | + var shortdate = DateTime.Now.ToString("yyyy-MM-dd"); |
| 266 | + var shortdateWithTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"); |
| 267 | + |
| 268 | + var dumpPath = $"Logs\\MiniDumpT{Thread.CurrentThread.ManagedThreadId}-{shortdateWithTime}.dmp"; |
| 269 | + Log.Info($"Generating minidump at {dumpPath}"); |
| 270 | + var dumpFlags = MyMiniDump.Options.Normal | MyMiniDump.Options.WithProcessThreadData | MyMiniDump.Options.WithThreadInfo; |
| 271 | + MyVRage.Platform.CrashReporting.WriteMiniDump(dumpPath, dumpFlags, IntPtr.Zero); |
| 272 | + |
| 273 | + if (Config.SendLogsToKeen) |
| 274 | + { |
| 275 | + List<string> additionalFiles = new List<string>(); |
| 276 | + if (File.Exists(dumpPath)) |
| 277 | + additionalFiles.Add(dumpPath); |
| 278 | + |
| 279 | + CrashInfo info = MyErrorReporter.BuildCrashInfo(); |
| 280 | + MyErrorReporter.ReportNotInteractive($"Logs\\Keen-{shortdate}.log", info.AnalyticId, false, |
| 281 | + additionalFiles.ToList(), true, string.Empty, string.Empty, info); |
| 282 | + } |
| 283 | + |
| 284 | + if(Config.DeleteMiniDumps) |
| 285 | + File.Delete(dumpPath); |
| 286 | + } |
| 287 | + |
258 | 288 | private void HandleException(object sender, UnhandledExceptionEventArgs e) |
259 | 289 | { |
260 | 290 | _server.FatalException = true; |
261 | 291 | var ex = (Exception)e.ExceptionObject; |
262 | 292 | LogException(ex); |
263 | | - if (MyFakes.ENABLE_MINIDUMP_SENDING) |
264 | | - { |
265 | | - string path = Path.Combine(MyFileSystem.UserDataPath, "Minidump.dmp"); |
266 | | - Log.Info($"Generating minidump at {path}"); |
267 | | - Log.Error("Keen broke the minidump, sorry."); |
268 | | - //MyMiniDump.Options options = MyMiniDump.Options.WithProcessThreadData | MyMiniDump.Options.WithThreadInfo; |
269 | | - //MyMiniDump.Write(path, options, MyMiniDump.ExceptionInfo.Present); |
270 | | - } |
| 293 | + SendAndDump(); |
271 | 294 | LogManager.Flush(); |
272 | 295 | if (Config.RestartOnCrash) |
273 | 296 | { |
|
0 commit comments