6 using System.Diagnostics;
15 static StreamWriter Logger;
16 static bool IsInitialized =
false;
17 static bool IsOk =
false;
19 private static object Locker =
new object();
21 private static string _Filename =
".\\DirectOutput.log";
31 get {
return _Filename; }
32 set { _Filename = value; }
49 Logger.WriteLine(
"---------------------------------------------------------------------------------");
50 Logger.WriteLine(
"{0}\t{1}", DateTime.Now.ToString(
"yyyy.MM.dd HH:mm:ss.fff"),
"DirectOutput Logger initialized");
52 Version V = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
53 DateTime BuildDate =
new DateTime(2000, 1, 1).AddDays(V.Build).AddSeconds(V.Revision * 2);
54 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")));
58 Debug(
"Writting of debug log messages is enabled");
83 Write(
"Logging stopped");
87 IsInitialized =
false;
98 public static void Write(
string Message)
108 if (Message.IsNullOrWhiteSpace())
110 Logger.WriteLine(
"{0}\t{1}", DateTime.Now.ToString(
"yyyy.MM.dd HH:mm:ss.fff"),
"");
114 foreach (
string M
in Message.Split(
new[] {
'\r',
'\n' }))
116 Logger.WriteLine(
"{0}\t{1}", DateTime.Now.ToString(
"yyyy.MM.dd HH:mm:ss.fff"), M);
133 public static void Warning(
string Message)
135 Write(
"Warning: {0}".Build(Message));
143 public static void Exception(
string Message =
"", Exception E = null)
147 if (!Message.IsNullOrWhiteSpace())
149 Write(
"EXCEPTION: {0}".Build(Message));
153 Write(
"EXCEPTION: {0}".Build(E.Message));
155 foreach (
string S
in E.StackTrace.Split(
new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
157 Write(
"EXCEPTION: Stacktrace: {0}".Build(S));
160 if (E.TargetSite != null)
162 Write(
"EXCEPTION: Targetsite: {0}".Build(E.TargetSite.ToString()));
170 StackTrace ST =
new StackTrace(E,
true);
172 StackFrame Frame = ST.GetFrame(0);
174 int Line = Frame.GetFileLineNumber();
175 string ExceptionFilename = Frame.GetFileName();
177 Write(
"EXCEPTION: Location: LineNr {0} in {1]".Build(Line, ExceptionFilename));
182 while (E.InnerException != null)
184 E = E.InnerException;
185 Write(
"EXCEPTION: InnerException {0}: {1}".Build(Level, E.Message));
201 public static void Exception(Exception E = null)
213 [Conditional(
"DEBUGLOG")]
214 public static void Debug(
string Message =
"")
216 Write(
"Debug: {0}".Build(Message));