using AIStudio.Tools.Rust;
namespace AIStudio.Tools.Services;
public sealed partial class RustService
{
///
/// Get the paths of the log files.
///
/// The paths of the log files.
public async Task GetLogPaths()
{
return await this.http.GetFromJsonAsync("/log/paths", this.jsonRustSerializerOptions);
}
///
/// Sends a log event to the Rust runtime.
///
/// The timestamp of the log event.
/// The log level.
/// The category of the log event.
/// The log message.
/// Optional exception message.
/// Optional exception stack trace.
public void LogEvent(string timestamp, string level, string category, string message, string? exception = null, string? stackTrace = null)
{
try
{
// Fire-and-forget the log event to avoid blocking:
var request = new LogEventRequest(timestamp, level, category, message, exception, stackTrace);
_ = this.http.PostAsJsonAsync("/log/event", request, this.jsonRustSerializerOptions);
}
catch
{
//
// We don't expect this to ever happen because the HTTP client cannot raise exceptions in fire-and-forget mode.
// This is because we don't await the task, so any exceptions thrown during the HTTP request are not propagated
// back to the caller.
//
Console.WriteLine("Failed to send log event to Rust service.");
// Ignore errors to avoid log loops
}
}
}