SafeDispatch/TCPServerService/Utils.cs
2024-02-22 18:43:59 +02:00

42 lines
1.2 KiB
C#

using System;
using System.Diagnostics;
namespace TCPServerService
{
public class Utils
{
private static readonly object locker = new object();
public static bool TimeWithMs = false;
public static void WriteEventLog(String source, String content, EventLogEntryType type, Int32 eventId)
{
try
{
if (!EventLog.SourceExists(source))
EventLog.CreateEventSource(source, "Application");
EventLog.WriteEntry(source, content, type, eventId);
}
catch (Exception ex)
{
Utils.WriteLine("Could not write to event log :" + ex.ToString(), ConsoleColor.Red);
}
}
public static void WriteLine(string str, ConsoleColor color)
{
lock (locker)
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(String.Format("[### {0:H:mm:ss" + (TimeWithMs ? ".ffffff" : "") + "} ###] ", DateTime.Now));
Console.ForegroundColor = color;
Console.Write(String.Format("{0}\n", str));
Console.ForegroundColor = ConsoleColor.Gray;
}
}
}
}