1) Write in Code behind
private void Page_Load(object sender, System.EventArgs e)
{
try
{
int k = i/0; // Zero
}
catch (Exception ex)
{
writeLog("Error Found on " + DateTime);
writeLog("=================");
writeLog(ex.Message);
}
}
private void writeLog(string message)
{
try
{
string logFile = String.Empty;
StreamWriter logWriter;
logFile = ConfigurationSettings.AppSettings["LogFilePath"];
if (File.Exists(logFile))
{
logWriter = File.AppendText(logFile);
}
else
{
logWriter = File.CreateText(logFile);
}
logWriter.WriteLine(message);
logWriter.Close();
}
catch(Exception e)
{
Console.Out.WriteLine("Error in writing log :" + e.Message);
}
}
2) Write in the Config File
Ritesh Kumar Kesharwani
A D I T I , B A N G A L O R E
Software Professional
Cell : 91-9845657636
Page:
Yahoo! Photos Got holiday prints? See all the ways to get quality prints in your hands ASAP.
1 comment:
Thanks dude!!!
It really helped me.
Raj Gupta
Mumbai
Post a Comment