16 static StreamWriter Logger;
17 static bool IsInitialized =
false;
18 static bool IsOk =
false;
20 private static object Locker =
new object();
22 private static string _Filename =
".\\DirectOutput.log";
32 get {
return _Filename; }
33 set { _Filename = value; }
50 Logger.WriteLine(
"---------------------------------------------------------------------------------");
51 Logger.WriteLine(
"{0}\t{1}", DateTime.Now.ToString(
"yyyy.MM.dd HH:mm:ss.fff"),
"DirectOutput Logger initialized");
53 Version V =
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
54 DateTime BuildDate =
new DateTime(2000, 1, 1).AddDays(V.Build).AddSeconds(V.Revision * 2);
55 Logger.WriteLine(
"{0}\t{1}", DateTime.Now.ToString(
"yyyy.MM.dd HH:mm:ss.fff"),
"DirectOutput Version {0} as of {1}".Build(V.ToString(), BuildDate.ToString(
"yyyy.MM.dd HH:mm")));
84 Write(
"Logging stopped");
88 IsInitialized =
false;
99 public static void Write(
string Message)
109 if (Message.IsNullOrWhiteSpace())
111 Logger.WriteLine(
"{0}\t{1}", DateTime.Now.ToString(
"yyyy.MM.dd HH:mm:ss.fff"),
"");
115 foreach (
string M
in Message.Split(
new[] {
'\r',
'\n' }))
117 Logger.WriteLine(
"{0}\t{1}", DateTime.Now.ToString(
"yyyy.MM.dd HH:mm:ss.fff"), M);
136 Write(
"Warning: {0}".Build(Message));
148 if (!Message.IsNullOrWhiteSpace())
150 Write(
"EXCEPTION: {0}".Build(Message));
152 Write(
"EXCEPTION: Thread: {0}".Build(Thread.CurrentThread.Name));
155 Write(
"EXCEPTION: Message: {0} --> {1}".Build(E.GetType().Name, E.Message));
157 foreach (
string S
in E.StackTrace.Split(
new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
159 Write(
"EXCEPTION: Stacktrace: {0}".Build(S));
162 if (E.TargetSite != null)
164 Write(
"EXCEPTION: Targetsite: {0}".Build(E.TargetSite.ToString()));
172 StackTrace ST =
new StackTrace(E,
true);
174 StackFrame Frame = ST.GetFrame(0);
176 int Line = Frame.GetFileLineNumber();
177 string ExceptionFilename = Frame.GetFileName();
179 Write(
"EXCEPTION: Location: LineNr {0} in {1]".Build(Line, ExceptionFilename));
184 while (E.InnerException != null)
186 E = E.InnerException;
187 Write(
"EXCEPTION: InnerException {0}: {1} --> {2}".Build(Level, E.GetType().Name, E.Message));
216 public static void Debug(
string Message =
"")
218 Write(
"Debug: {0}".Build(Message));
static void Finish()
Finishes the logger. Closes the log file.
static void Warning(string Message)
Writes a warning message to the log.
static void Write(string Message)
Writes the specified message to the logfile.
static void Init()
Initializes the log using the file defnied in the Filename property.
A simple logger used to record important events and exceptions.
static void Debug(string Message="")
Writes the specified debug message to the log file.
static void Exception(Exception E)
Writes a exception to the log.
static string Filename
Gets or sets the filename for the log.
static void Exception(string Message, Exception E=null)
Writes a exception message to the log.