초기커밋
This commit is contained in:
49
ServerCore/Dump/DumpHandler.cs
Normal file
49
ServerCore/Dump/DumpHandler.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
|
||||
|
||||
namespace ServerCore;
|
||||
|
||||
public struct DumpConfig
|
||||
{
|
||||
public string DumpFile;
|
||||
public string TxtFile;
|
||||
}
|
||||
|
||||
public static class DumpHandler
|
||||
{
|
||||
public static void unhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
var exception = e.ExceptionObject as Exception;
|
||||
File.WriteAllText("unhandled_exception.log", exception?.ToString());
|
||||
|
||||
writeTxt(DumpHelper.DumpConfig, exception);
|
||||
}
|
||||
|
||||
public static void writeTxt(DumpConfig dumpCopnfig, Exception? e)
|
||||
{
|
||||
using (var fs = new FileStream(dumpCopnfig.TxtFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
|
||||
{
|
||||
using (StreamWriter writer = new StreamWriter(fs))
|
||||
{
|
||||
writer.WriteLine("================================================================================================");
|
||||
writer.WriteLine("Date : " + DateTime.Now.ToString());
|
||||
writer.WriteLine();
|
||||
|
||||
Exception? exception = e;
|
||||
while (exception != null)
|
||||
{
|
||||
writer.WriteLine($"{exception}");
|
||||
writer.WriteLine("================================================================================================");
|
||||
|
||||
exception = exception.InnerException;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user