Wednesday, May 23, 2007

Error Report Example in C#

public class CreateErrorLog
{
#region Variables
private string m_sLogFormat;
private string m_sErrorTime;
#endregion

#region Properties
//get and set - public access of private members
public string LogFormat
{
get
{
return m_sLogFormat;
}
set
{
m_sLogFormat = value;
}
}
public string ErrorTime
{
get
{
return m_sErrorTime;
}
set
{
m_sErrorTime = value;
}
}
#endregion

#region Constructor
public CreateErrorLog()
{
// TODO: Add constructor logic here
m_sLogFormat = "[2T]"+ DateTime.Now.ToShortDateString().ToString()+" "+DateTime.Now.ToLongTimeString().ToString()+" ==> ";
string sYear = DateTime.Now.Year.ToString();
string sMonth = DateTime.Now.Month.ToString();
string sDay = DateTime.Now.Day.ToString();
m_sErrorTime = sYear+sMonth+sDay;
}
~CreateErrorLog(){}
#endregion

#region Functions
public void ErrorLog(string sPathName, string sErrMsg)
{
StreamWriter sw = File.AppendText(sPathName+m_sErrorTime+".txt");
sw.WriteLine(m_sLogFormat + sErrMsg);
sw.Flush();
sw.Close();
}
#endregion
}

No comments: