Files
abysmal-isle/Scripts/Misc/Timestamp.cs
Unstable Kitsune b918192e4e Overwrite
Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
2023-11-28 23:20:26 -05:00

66 lines
1.6 KiB
C#

using System;
using System.IO;
using System.Text;
namespace System
{
public class ConsoleHook : TextWriter
{
#if DEBUG
private static readonly bool _Enabled = false;
#else
private static readonly bool _Enabled = true;
#endif
private static Stream m_OldOutput;
private static bool m_Newline;
public override Encoding Encoding
{
get
{
return Encoding.ASCII;
}
}
private string Timestamp
{
get
{
return String.Format("{0:D2}:{1:D2}:{2:D2} ", DateTime.UtcNow.Hour, DateTime.UtcNow.Minute, DateTime.UtcNow.Second);
}
}
public static void Initialize()
{
if (_Enabled)
{
m_OldOutput = Console.OpenStandardOutput();
Console.SetOut(new ConsoleHook());
m_Newline = true;
}
}
public override void WriteLine(string value)
{
if (m_Newline)
{
value = this.Timestamp + value;
}
byte[] data = this.Encoding.GetBytes(value);
m_OldOutput.Write(data, 0, data.Length);
m_OldOutput.WriteByte(10);
m_Newline = true;
}
public override void Write(string value)
{
if (m_Newline)
{
value = this.Timestamp + value;
}
byte[] data = this.Encoding.GetBytes(value);
m_OldOutput.Write(data, 0, data.Length);
m_Newline = false;
}
}
}