2023-03-21 16:14:46 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.Json;
|
2019-02-11 04:00:32 -08:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Common.Logging
|
|
|
|
|
{
|
|
|
|
|
public class JsonLogTarget : ILogTarget
|
|
|
|
|
{
|
|
|
|
|
private Stream _stream;
|
|
|
|
|
private bool _leaveOpen;
|
2019-12-21 11:52:31 -08:00
|
|
|
|
private string _name;
|
2019-02-11 04:00:32 -08:00
|
|
|
|
|
2019-12-21 11:52:31 -08:00
|
|
|
|
string ILogTarget.Name { get => _name; }
|
|
|
|
|
|
|
|
|
|
public JsonLogTarget(Stream stream, string name)
|
2019-02-11 04:00:32 -08:00
|
|
|
|
{
|
|
|
|
|
_stream = stream;
|
2019-12-21 11:52:31 -08:00
|
|
|
|
_name = name;
|
2019-02-11 04:00:32 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonLogTarget(Stream stream, bool leaveOpen)
|
|
|
|
|
{
|
|
|
|
|
_stream = stream;
|
|
|
|
|
_leaveOpen = leaveOpen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Log(object sender, LogEventArgs e)
|
|
|
|
|
{
|
2023-03-21 16:14:46 -07:00
|
|
|
|
string text = JsonSerializer.Serialize(e);
|
|
|
|
|
|
|
|
|
|
using (BinaryWriter writer = new BinaryWriter(_stream))
|
|
|
|
|
{
|
|
|
|
|
writer.Write(text);
|
|
|
|
|
}
|
2019-02-11 04:00:32 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
if (!_leaveOpen)
|
|
|
|
|
{
|
|
|
|
|
_stream.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|