초기커밋
This commit is contained in:
61
ServerCore/Dump/DotNetDumpHelper.cs
Normal file
61
ServerCore/Dump/DotNetDumpHelper.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
||||
|
||||
using Microsoft.Diagnostics.NETCore.Client;
|
||||
|
||||
|
||||
namespace ServerCore;
|
||||
|
||||
public static class DotNetDumpHelper
|
||||
{
|
||||
private static DumpConfig DumpConfig;
|
||||
|
||||
private static void unhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
if (e.ExceptionObject is Exception ex)
|
||||
{
|
||||
// 덤프 파일 생성 경로와 이름
|
||||
string dumpFile = $"{DumpConfig}_{DateTime.Now.Ticks}.dmp";
|
||||
string txtOutputFile = $"{DumpConfig}_{DateTime.Now.Ticks}.txt";
|
||||
|
||||
// 현재 프로세스 id 가져오기
|
||||
int processId = Process.GetCurrentProcess().Id;
|
||||
var client = new DiagnosticsClient(processId);
|
||||
|
||||
// 덤프 파일 생성
|
||||
try
|
||||
{
|
||||
client.WriteDump(DumpType.Normal, dumpFile, logDumpGeneration: true);
|
||||
}
|
||||
catch (Exception dumpEx)
|
||||
{
|
||||
Log.getLogger().error($"Exception !!!, WriteDump() !!! - exception:{dumpEx}");
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
DumpConfig.TxtFile = txtOutputFile;
|
||||
// 예외 정보 및 프로세스 정보를 텍스트 파일로 저장
|
||||
DumpHandler.writeTxt(DumpConfig, ex);
|
||||
}
|
||||
catch (Exception txtEx)
|
||||
{
|
||||
Log.getLogger().error($"Exception !!!, DumpHandler.write() !!! - exception:{txtEx}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void init(string dumpPath, string name)
|
||||
{
|
||||
// 경로 및 이름 설정
|
||||
DumpConfig.DumpFile = $"{dumpPath}/{name}";
|
||||
|
||||
// 예외 처리 핸들러 등록
|
||||
AppDomain.CurrentDomain.UnhandledException += unhandledExceptionHandler;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user