// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using EpicGames.Core;
using Microsoft.Extensions.Logging;
namespace UnrealBuildBase
{
///
/// Implementation of that captures a full structured logging event.
///
/// The inner exception
/// Event to construct from
public class BuildLogEventException(Exception? InnerException, LogEvent Event) : UnrealBuildTool.BuildException(InnerException, Event.ToString())
{
///
/// The event object
///
public LogEvent Event { get; } = Event;
///
/// Constructor
///
/// Event to construct from
public BuildLogEventException(LogEvent Event)
: this(null, Event)
{
}
///
public BuildLogEventException(string Format, params object[] Arguments)
: this(LogEvent.Create(LogLevel.Error, Format, Arguments))
{
}
///
public BuildLogEventException(Exception? InnerException, string Format, params object[] Arguments)
: this(InnerException, LogEvent.Create(LogLevel.Error, default, InnerException, Format, Arguments))
{
}
///
/// Constructor which wraps another exception
///
/// Event id for the error
/// Inner exception to wrap
/// Structured logging format string
/// Argument objects
public BuildLogEventException(Exception? InnerException, EventId EventId, string Format, params object[] Arguments)
: this(InnerException, LogEvent.Create(LogLevel.Error, EventId, InnerException, Format, Arguments))
{
}
///
public override void LogException(ILogger Logger)
{
Logger.Log(Event.Level, Event.Id, Event, this, (s, e) => s.ToString());
Logger.LogDebug(Event.Id, this, "{Ex}", ExceptionUtils.FormatExceptionDetails(this));
}
}
}