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