Posted at

UnityのExceptionのStackTraceをサーバなどに送りたい

ILogHandlerで頑張るのかなと思ったら、Application.logMessageReceivedのほうで取れるらしいのですね。


LogReporter.cs

using System;

using UniRx.Async;
using UnityEngine;

namespace Tonari.Unity.LogSystem
{
public class LogReporter : IDisposable
{
public LogReporter()
{
Application.logMessageReceived += LogCallBackHandler;
}

public void Dispose()
{
Application.logMessageReceived -= LogCallBackHandler;
}

private void LogCallBackHandler(string condition, string stackTrace, LogType logType)
{
ReportLogAsync(condition, stackTrace, logType).Forget();
}

private UniTask ReportLogAsync(string condition, string stackTrace, LogType logType)
{
// ここでサーバに送ればいい

return UniTask.CompletedTask;
}
}
}