From 362f120efd3076fbf4667b645d0457cb2207bc6a Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Tue, 18 Apr 2017 22:05:35 +0000 Subject: [PATCH] Add LogObject --- OwnObject.cs | 61 ++++++++++++++++++++++++++++++-------- Properties/AssemblyInfo.cs | 4 +-- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/OwnObject.cs b/OwnObject.cs index 3030043..be98b00 100644 --- a/OwnObject.cs +++ b/OwnObject.cs @@ -7,7 +7,37 @@ namespace BlubbFish.Utils { abstract public class OwnObject { - private List> loglist = new List>(); + public class LogObject { + public LogObject(DateTime date, String location, String message, LogLevel level) { + this.Date = date; + this.Location = location; + this.Message = message; + this.Level = level; + } + + public DateTime Date { get; set; } + public String Location { get; set; } + public String Message { get; set; } + public LogLevel Level { get; set; } + /// + /// Formates a LogMessage to a String + /// + /// Formated String + public override String ToString() { + return "[" + this.Date.ToString("R") + "]: " + this.Level.ToString() + " "+ this.Location + ", " + this.Message; + } + /// + /// Formates a LogMessage to a String + /// + /// Enables the output of the location + /// Enables the output of the date + /// Formated String + public String ToString(Boolean classNames, Boolean timeStamps) { + return (timeStamps ? "[" + this.Date.ToString("R") + "]: " + this.Level.ToString() + " " : "") + (classNames ? this.Location + ", " : "") + this.Message; + } + } + + private List loglist = new List(); public delegate void LogEvent(String location, String message, LogLevel level, DateTime date); public enum LogLevel : Int32 { @@ -28,30 +58,34 @@ namespace BlubbFish.Utils /// /// Get the Complete Log /// - public List GetLog(LogLevel level, Boolean classNames, Boolean timeStamps) - { + public List GetLog(LogLevel level, Boolean classNames, Boolean timeStamps) { List ret = new List(); - foreach (Tuple t in this.loglist) { - if (t.Item4 >= level) { - ret.Add(LogToString(t.Item2, t.Item3, t.Item4, t.Item1, classNames, timeStamps)); + foreach (LogObject t in this.loglist) { + if (t.Level >= level) { + ret.Add(t.ToString(classNames, timeStamps)); } } return ret; } /// - /// Formates a LogMessage to a String + /// Put a message in the log /// - public static String LogToString(String location, String message, LogLevel level, DateTime date, Boolean classNames, Boolean timeStamps) - { - return (timeStamps ? "[" + date.ToString("R") + "]: " + level.ToString() + " " : "") + (classNames ? location + ", " : "") + message; - } - + /// Where the event arrives + /// The logmessage itselfs + /// Level of the message protected void AddLog(String location, String message, LogLevel level) { this.AddLog(location, message, level, DateTime.Now); } + /// + /// Put a message in the log + /// + /// Where the event arrives + /// The logmessage itselfs + /// Level of the message + /// Date of the message protected void AddLog(String location, String message, LogLevel level, DateTime date) { if (EventDebug != null && level >= LogLevel.Debug) { @@ -70,7 +104,8 @@ namespace BlubbFish.Utils EventError(location, message, level, date); } EventLog?.Invoke(location, message, level, date); - this.loglist.Add(new Tuple(date, location, message, level)); + + this.loglist.Add(new LogObject(date, location, message, level)); } } } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index e8e4af1..d5aa52e 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.2.3")] -[assembly: AssemblyFileVersion("1.0.2.3")] +[assembly: AssemblyVersion("1.0.2.5")] +[assembly: AssemblyFileVersion("1.0.2.5")]