mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-06 17:58:05 +02:00
* 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.
39 lines
1.1 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|