1)Good logging module - like log4net
2)Good logging format code so that reading the log to find out
error is easier-- find out!!
eg: datetime :classname :method Name :message
3) Simple logging code is shown below
to be continued...
2)Good logging format code so that reading the log to find out
error is easier-- find out!!
eg: datetime :classname :method Name :message
3) Simple logging code is shown below
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace Common { public class Logger { private static string _logFileName = string.Empty; /// <summary> /// Create a statis logger instance for your project /// </summary> /// <param name="filename">Log file name</param> public Logger(string filename = "log.txt") { _logFileName = filename; } /// <summary> /// Used to log an exception information /// </summary> /// <param name="ex"></param> /// <param name="classname"></param> /// <param name="methodName"></param> /// <param name="msg"></param> public void WriteEx(Exception ex, string classname = "", string methodName = "", string msg = "") { try { StreamWriter sw = new StreamWriter(_logFileName, true); sw.WriteLine(string.Format("{0} : {1} : {2} : {3} : {4} ", DateTime.UtcNow.ToShortDateString(), classname, methodName, ex.Message, msg)); } catch { //Do nothing } } /// <summary> /// Used to log any information /// </summary> /// <param name="ex"></param> /// <param name="classname"></param> /// <param name="methodName"></param> /// <param name="msg"></param> public void WriteMsg(string msg, string classname = "", string methodName = "") { try { StreamWriter sw = new StreamWriter(_logFileName, true); sw.WriteLine(string.Format("{0} : {1} : {2} : {3} ", DateTime.UtcNow.ToShortDateString(), classname, methodName, msg)); } catch { //Do nothing } } } }
to be continued...
No comments:
Post a Comment