2019-12-21 14:52:31 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2019-02-11 07:00:32 -05:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Common.Logging
|
|
|
|
|
{
|
|
|
|
|
public class FileLogTarget : ILogTarget
|
|
|
|
|
{
|
|
|
|
|
private static readonly ObjectPool<StringBuilder> _stringBuilderPool = SharedPools.Default<StringBuilder>();
|
|
|
|
|
|
|
|
|
|
private readonly StreamWriter _logWriter;
|
|
|
|
|
private readonly ILogFormatter _formatter;
|
2019-12-21 14:52:31 -05:00
|
|
|
|
private readonly string _name;
|
2019-02-11 07:00:32 -05:00
|
|
|
|
|
2019-12-21 14:52:31 -05:00
|
|
|
|
string ILogTarget.Name { get => _name; }
|
|
|
|
|
|
|
|
|
|
public FileLogTarget(string path, string name)
|
|
|
|
|
: this(path, name, FileShare.Read, FileMode.Append)
|
2019-02-11 07:00:32 -05:00
|
|
|
|
{ }
|
|
|
|
|
|
2019-12-21 14:52:31 -05:00
|
|
|
|
public FileLogTarget(string path, string name, FileShare fileShare, FileMode fileMode)
|
2019-02-11 07:00:32 -05:00
|
|
|
|
{
|
2019-12-21 14:52:31 -05:00
|
|
|
|
_name = name;
|
2019-02-11 07:00:32 -05:00
|
|
|
|
_logWriter = new StreamWriter(File.Open(path, fileMode, FileAccess.Write, fileShare));
|
|
|
|
|
_formatter = new DefaultLogFormatter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Log(object sender, LogEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
_logWriter.WriteLine(_formatter.Format(args));
|
|
|
|
|
_logWriter.Flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_logWriter.WriteLine("---- End of Log ----");
|
|
|
|
|
_logWriter.Flush();
|
|
|
|
|
_logWriter.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|