Thursday, October 3, 2013
Write log for application
private void WriteLogToFile(string errorSource, string message, Exception exception, bool isNewLine)
{
try
{
//
FileStream fs = new FileStream(ConfigurationManager.AppSettings.Get("ErrorLog"), FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
StreamWriter errorLog = new StreamWriter(fs);
if (isNewLine)
errorLog.WriteLine("-".PadRight(100, '-'));
errorLog.WriteLine(DateTime.Now);
if (errorSource != null)
errorLog.WriteLine(errorSource);
if (message != null)
errorLog.WriteLine(message);
if (exception != null)
errorLog.WriteLine(exception);
errorLog.Close();
fs.Close();
fs.Dispose();
}
catch (Exception ex)
{
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment