init
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace DbAPIUI.Logging
|
||||
{
|
||||
public class LogManager
|
||||
{
|
||||
private static TraceSource MySource = null;
|
||||
private static readonly object MyLock = new object();
|
||||
public enum LogEvents
|
||||
{
|
||||
Application,
|
||||
Message,
|
||||
Connections,
|
||||
DAS,
|
||||
Sensors,
|
||||
TestSetups,
|
||||
Tags
|
||||
}
|
||||
public static void Log(TraceEventType eventType, LogEvents logEvent, string msg)
|
||||
{
|
||||
InitializeSource();
|
||||
MySource.TraceEvent(eventType, (int)logEvent, msg);
|
||||
var dt = DateTime.Now;
|
||||
Form1.UpdateScreenLog($"{dt.Year}-{dt.Month:00}-{dt.Day:00} {dt.Hour:00}:{dt.Minute:00}:{dt.Second}.{dt.Millisecond:000} {msg}");
|
||||
}
|
||||
private static void InitializeSource()
|
||||
{
|
||||
lock (MyLock)
|
||||
{
|
||||
if( null != MySource)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MySource = new TraceSource("DbAPIUI");
|
||||
MySource.Listeners.Clear();
|
||||
Trace.AutoFlush = true;
|
||||
MySource.Listeners.Add(new TextWriterTraceListener("DBAPIUI.log", "log"));
|
||||
MySource.Listeners["log"].IndentLevel = 1;
|
||||
MySource.Listeners["log"].TraceOutputOptions = TraceOptions.DateTime | TraceOptions.Timestamp;
|
||||
MySource.Switch.Level = SourceLevels.All;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user