Files
RobustToolbox/Robust.Shared/Log/FileLogHandler.cs
T
AcruidandGitHub 2183cd7ca1 Massive Namespace Cleanup (#1544)
* Removed the Interfaces folder.
* All objects inside the GameObjects subfolders are now in the GameObjects namespace.
* Added a Resharper DotSettings file to mark the GameObjects subfolders as not providing namespaces.
* Simplified Robust.client.Graphics namespace.
* Automated remove redundant using statements.
2021-02-10 23:27:19 -08:00

39 lines
1.1 KiB
C#

using System;
using System.IO;
using Robust.Shared.Utility;
using Serilog.Events;
namespace Robust.Shared.Log
{
internal sealed class FileLogHandler : ILogHandler, IDisposable
{
private readonly TextWriter writer;
public FileLogHandler(string path)
{
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
writer = TextWriter.Synchronized(new StreamWriter(path, true, EncodingHelpers.UTF8));
}
public void Dispose()
{
writer.Dispose();
}
public void Log(string sawmillName, LogEvent message)
{
var name = LogMessage.LogLevelToName(message.Level.ToRobust());
writer.WriteLine("{0:o} [{1}] {2}: {3}", DateTime.Now, name, sawmillName, message.RenderMessage());
if (message.Exception != null)
{
writer.WriteLine(message.Exception.ToString());
}
// This probably isn't the best idea.
// Remove this flush if it becomes a problem (say performance).
writer.Flush();
}
}
}