Browse Source

refactor

master
Tobias Hübner 5 months ago
parent
commit
44a1a7cbcb
1 changed files with 12 additions and 9 deletions
  1. +12
    -9
      Logging/logging.cs

+ 12
- 9
Logging/logging.cs View File

@@ -13,7 +13,7 @@ using System.Text;

namespace logging
{
public enum Log_level
public enum LogLevel
{
Trace, Warning, Uncaught, Error
}
@@ -21,7 +21,7 @@ namespace logging
public interface Logger
{
void log(String format);
string format(Log_level ll, string messsage);
string format(LogLevel ll, string messsage);
}

public static class LogPoint
@@ -44,25 +44,25 @@ namespace logging
{
Exception e = (Exception)args.ExceptionObject;

log(e, Log_level.Uncaught);
log(e, LogLevel.Uncaught);

}
public static void log(Exception e, Log_level ll)
public static void log(Exception e, LogLevel ll)
{
log(e.ToString(), ll);
}

public static void log(Exception e)
{
log(e.ToString(), Log_level.Error);
log(e.ToString(), LogLevel.Error);
}

public static void log(string logtext)
{
log(logtext, Log_level.Trace);
log(logtext, LogLevel.Trace);
}

public static void log(string logtext, Log_level ll)
public static void log(string logtext, LogLevel ll)
{

if (logger != null)
@@ -102,7 +102,7 @@ namespace logging
sock.SendTo(Encoding.ASCII.GetBytes(format), endpoint);
}

public string format(Log_level ll, string messsage)
public string format(LogLevel ll, string messsage)
{
return $"{{ \"version\": \"1.1\", \"host\" : \"{Environment.MachineName}\",\"short_message\" : \"{messsage}\", \"user\" : \"{Environment.UserName}\", \"thread\" : \"{Thread.CurrentThread.ManagedThreadId}\", \"program_name\" : \"{program_name}\", \"log_level\" : \"{ll}\" }}"; ;
}
@@ -143,6 +143,7 @@ namespace logging
t.IsBackground = true;
t.Start();
}

void write(string s)
{
lock (this)
@@ -154,7 +155,7 @@ namespace logging
}
}

public string format(Log_level ll, string text)
public string format(LogLevel ll, string text)
{
string log = $"Level : {ll}\r\n" +
$"TS : {timestamp_string()}\r\n" +
@@ -163,10 +164,12 @@ namespace logging
return log;

}

private static string get_logfile_name()
{
return $"{Environment.UserName}@{Environment.MachineName}_{DateTime.Now.ToString("dd-MM-yy")}.log";
}

public void log(string format)
{
write_queue.Add(format);


Loading…
Cancel
Save