update 20241003
This commit is contained in:
179
Logging/Logging.cs
Normal file
179
Logging/Logging.cs
Normal file
@@ -0,0 +1,179 @@
|
||||
using NLog;
|
||||
using NLog.Time;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Logging
|
||||
{
|
||||
public class Logging
|
||||
{
|
||||
|
||||
private static readonly NLog.Logger Logger = NLog.LogManager.GetLogger("OnDoc");
|
||||
public static string connectionstring { get; set; } = "";
|
||||
public static string IntLogLevel { get; set; } = "";
|
||||
public static string IntUserID { get; set; } = "*";
|
||||
|
||||
public static void Info(string message, string herkunft, string zusatz)
|
||||
{
|
||||
if (DoLogging("Info") != true) { return; }
|
||||
GlobalDiagnosticsContext.Set("Herkunft", herkunft);
|
||||
GlobalDiagnosticsContext.Set("Zusatz", zusatz);
|
||||
Logger.Info(message);
|
||||
}
|
||||
public static void Warning(string message, string herkunft, string zusatz)
|
||||
{
|
||||
if (DoLogging("Warning") != true) { return; }
|
||||
GlobalDiagnosticsContext.Set("Herkunft", herkunft);
|
||||
GlobalDiagnosticsContext.Set("Zusatz", zusatz);
|
||||
Logger.Warn(message);
|
||||
}
|
||||
public static void Error(string message, string herkunft, string zusatz) {
|
||||
if (DoLogging("Error") != true) { return; }
|
||||
|
||||
GlobalDiagnosticsContext.Set("Herkunft",herkunft);
|
||||
GlobalDiagnosticsContext.Set("Zusatz", zusatz);
|
||||
Logger.Error(message);
|
||||
}
|
||||
|
||||
public static void Fatal(string message, string herkunft, string zusatz)
|
||||
{
|
||||
if (DoLogging("Fatal") != true) { return; }
|
||||
|
||||
GlobalDiagnosticsContext.Set("Herkunft", herkunft);
|
||||
GlobalDiagnosticsContext.Set("Zusatz", zusatz);
|
||||
Logger.Fatal(message);
|
||||
}
|
||||
public static void Trance(string message, string herkunft, string zusatz)
|
||||
{
|
||||
if (DoLogging("Trace") != true) { return; }
|
||||
|
||||
GlobalDiagnosticsContext.Set("Herkunft", herkunft);
|
||||
GlobalDiagnosticsContext.Set("Zusatz", zusatz);
|
||||
Logger.Trace(message);
|
||||
}
|
||||
public static void Debug(string message, string herkunft, string zusatz)
|
||||
{
|
||||
if (DoLogging("Debug") != true) { return; }
|
||||
|
||||
GlobalDiagnosticsContext.Set("Herkunft", herkunft);
|
||||
GlobalDiagnosticsContext.Set("Zusatz", zusatz);
|
||||
Logger.Debug(message);
|
||||
}
|
||||
|
||||
|
||||
private static Boolean DoLogging(string Loglevel)
|
||||
{
|
||||
if (IntUserID != "*")
|
||||
{
|
||||
if (IntUserID.Contains(System.Security.Principal.WindowsIdentity.GetCurrent().Name))
|
||||
{
|
||||
if (IntLogLevel.Contains(Loglevel))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IntLogLevel.Contains(Loglevel))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public class DocLog
|
||||
{
|
||||
|
||||
private static readonly NLog.Logger Logger = NLog.LogManager.GetLogger("DocLog");
|
||||
|
||||
public static string connectionstring { get; set; } = "";
|
||||
public static string IntLogLevel { get; set; } = "";
|
||||
public static string IntUserID { get; set; } = "*";
|
||||
|
||||
public static void Info(string message, string herkunft, string dokumentid, string partnernr, string aktion)
|
||||
{
|
||||
if (DoLogging("Info") != true) { return; }
|
||||
GlobalDiagnosticsContext.Set("Herkunft", herkunft);
|
||||
GlobalDiagnosticsContext.Set("Dokumentid", dokumentid);
|
||||
GlobalDiagnosticsContext.Set("Partnernr",partnernr);
|
||||
GlobalDiagnosticsContext.Set("Aktion", aktion);
|
||||
Logger.Info(message);
|
||||
|
||||
}
|
||||
public static void Warning(string message, string herkunft, string dokumentid, string partnernr, string aktion)
|
||||
{
|
||||
if (DoLogging("Warning") != true) { return; }
|
||||
GlobalDiagnosticsContext.Set("Herkunft", herkunft);
|
||||
GlobalDiagnosticsContext.Set("Dokumentid", dokumentid);
|
||||
GlobalDiagnosticsContext.Set("Partnernr", partnernr);
|
||||
GlobalDiagnosticsContext.Set("Aktion", aktion);
|
||||
Logger.Warn(message);
|
||||
}
|
||||
public static void Error(string message, string herkunft, string dokumentid, string partnernr, string aktion)
|
||||
{
|
||||
if (DoLogging("Error") != true) { return; }
|
||||
GlobalDiagnosticsContext.Set("Herkunft", herkunft);
|
||||
GlobalDiagnosticsContext.Set("Dokumentid", dokumentid);
|
||||
GlobalDiagnosticsContext.Set("Partnernr", partnernr);
|
||||
GlobalDiagnosticsContext.Set("Aktion", aktion);
|
||||
Logger.Error(message);
|
||||
}
|
||||
|
||||
public static void Fatal(string message, string herkunft, string dokumentid, string partnernr, string aktion)
|
||||
{
|
||||
if (DoLogging("Fatal") != true) { return; }
|
||||
GlobalDiagnosticsContext.Set("Herkunft", herkunft);
|
||||
GlobalDiagnosticsContext.Set("Dokumentid", dokumentid);
|
||||
GlobalDiagnosticsContext.Set("Partnernr", partnernr);
|
||||
GlobalDiagnosticsContext.Set("Aktion", aktion);
|
||||
Logger.Fatal(message);
|
||||
}
|
||||
public static void Trance(string message, string herkunft, string dokumentid, string partnernr, string aktion)
|
||||
{
|
||||
if (DoLogging("Trace") != true) { return; }
|
||||
GlobalDiagnosticsContext.Set("Herkunft", herkunft);
|
||||
GlobalDiagnosticsContext.Set("Dokumentid", dokumentid);
|
||||
GlobalDiagnosticsContext.Set("Partnernr", partnernr);
|
||||
GlobalDiagnosticsContext.Set("Aktion", aktion);
|
||||
Logger.Trace(message);
|
||||
}
|
||||
public static void Debug(string message, string herkunft, string dokumentid, string partnernr, string aktion)
|
||||
{
|
||||
if (DoLogging("Debug") != true) { return; }
|
||||
GlobalDiagnosticsContext.Set("Herkunft", herkunft);
|
||||
GlobalDiagnosticsContext.Set("Dokumentid", dokumentid);
|
||||
GlobalDiagnosticsContext.Set("Partnernr", partnernr);
|
||||
GlobalDiagnosticsContext.Set("Aktion", aktion);
|
||||
Logger.Debug(message);
|
||||
}
|
||||
|
||||
|
||||
private static Boolean DoLogging(string Loglevel)
|
||||
{
|
||||
if (IntUserID != "*")
|
||||
{
|
||||
if (IntUserID.Contains(System.Security.Principal.WindowsIdentity.GetCurrent().Name))
|
||||
{
|
||||
if (IntLogLevel.Contains(Loglevel))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IntLogLevel.Contains(Loglevel))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user