65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
using Microsoft.Diagnostics.NETCore.Client;
|
|
|
|
|
|
namespace ServerCore;
|
|
|
|
|
|
// HANDOVER: .Net 전용 DiagnosticsClient 기반 예외 이벤트를 수신 받는 클래스 이다. (리눅스 환겨에서 정상적인 호출을 보장하지 않는다 !!!)
|
|
|
|
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;
|
|
}
|
|
}
|