12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using System.Diagnostics;
- namespace Log
- {
- public static class Log
- {
- public static void Init(string logPath)
- {
- Debug.Listeners.Clear();
- Debug.Listeners.Add(new TextWriterTraceListener(logPath));
- Debug.AutoFlush = true;
- }
- public static void D(string message)
- {
- var sf = new StackFrame(1, true);
- string log = string.Format(
- "{0} {1} Line:{2} {3} [D]: {4}",
- System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- sf.GetFileName(),
- sf.GetFileLineNumber(),
- sf.GetMethod(),
- message
- );
- Debug.WriteLine(log);
- }
- public static void D(string message, params object[] args)
- {
- string info = String.Format(message, args);
- var sf = new StackFrame(1, true);
- string log = string.Format(
- "{0} {1} Line:{2} {3} [D]: {4}",
- System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- sf.GetFileName(),
- sf.GetFileLineNumber(),
- sf.GetMethod(),
- info
- );
- Debug.WriteLine(log);
- }
- public static void E(string message)
- {
- var sf = new StackFrame(1, true);
- string log = string.Format(
- "{0} {1} Line:{2} {3} [E]: {4}",
- System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- sf.GetFileName(),
- sf.GetFileLineNumber(),
- sf.GetMethod(),
- message
- );
- Debug.WriteLine(log);
- }
- public static void E(string message, params object[] args)
- {
- string info = String.Format(message, args);
- var sf = new StackFrame(1, true);
- string log = string.Format(
- "{0} {1} Line:{2} {3} [E]: {4}",
- System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- sf.GetFileName(),
- sf.GetFileLineNumber(),
- sf.GetMethod(),
- info
- );
- Debug.WriteLine(log);
- }
- }
- }
|