Files
DP44/DataPRO/DbAPIUI/.svn/pristine/dd/ddc6c53a6e35012bb6fe3cc86479de1b607e2312.svn-base

46 lines
1.5 KiB
Plaintext
Raw Normal View History

2026-04-17 14:55:32 -04:00
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;
}
}
}
}