1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- using System.Text;
- using System.IO;
- namespace Vinno.IdentificationCardApp
- {
- public class Logger
- {
- private static readonly object Locker = new object();
- private static string LogDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "IDCardToolLogs");
- static Logger()
- {
- }
- private static string FilePath
- {
- get { return Path.Combine(LogDir, DateTime.Now.ToString("yyyyMMdd") + ".txt"); }
- }
- private static void Write(string msg)
- {
- lock (Locker)
- {
- if (!File.Exists(FilePath))
- {
- if (!Directory.Exists(LogDir))
- Directory.CreateDirectory(LogDir);
- }
- using (var writer = new StreamWriter(FilePath, true, Encoding.UTF8))
- {
- writer.WriteLine(msg);
- }
- }
- }
- public static void Debug(string msg)
- {
- msg = string.Format("[{0} {1}] : {2}", "Debug", DateTime.Now, msg);
- Write(msg);
- }
- public static void Info(string msg)
- {
- msg = string.Format("[{0} {1}] : {2}", "Info", DateTime.Now, msg);
- Write(msg);
- }
- public static void Error(string msg)
- {
- msg = string.Format("[{0} {1}] : {2}", "Error", DateTime.Now, msg);
- Write(msg);
- }
- public static void Error(string desc, Exception exception)
- {
- var msg = string.Format("[{0} {1}] : {2} {3}", "Error", DateTime.Now, desc, exception);
- Write(msg);
- }
- }
- }
|