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