mirror of
https://github.com/ServUO/ServUO
synced 2026-08-11 20:23:04 -04:00
- No code changes in this branch. This is simply clean up. Co-authored-by: TrueUO <knight.daniel.r@gmail.com>
56 lines
No EOL
1.4 KiB
C#
56 lines
No EOL
1.4 KiB
C#
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 => Encoding.ASCII;
|
|
|
|
private string Timestamp => 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 = Timestamp + value;
|
|
}
|
|
|
|
byte[] data = 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 = Timestamp + value;
|
|
}
|
|
|
|
byte[] data = Encoding.GetBytes(value);
|
|
m_OldOutput.Write(data, 0, data.Length);
|
|
m_Newline = false;
|
|
}
|
|
}
|
|
} |