关于Application_End事件运行的问题
jhhyq 2004-12-07 09:25:49 在Application_Start和Application_End中写日志,但是Application_End始终不运行
我把iis停了再启动,Application_Start到是每次都运行,而Application_End一次都没运行
不知道是不是哪里没设置对
protected void Application_End(Object sender, EventArgs e)
{
//write Application End Begin Time into Server Log
WriteLog("syslog/Server.txt","[ "+ DateTime.Now.ToString() + " ] Application_End");
}
/// <summary>
/// 写日志
/// </summary>
/// <param name="logFilePath">日志文件相对路径</param>
/// <param name="logTxt">写入的文本</param>
private void WriteLog(string logFilePath,string logTxt)
{
logFilePath=Server.MapPath(logFilePath);
if(!File.Exists(logFilePath))
{
try
{
//文件不存在,新建写入
StreamWriter sr=File.CreateText(logFilePath);
sr.WriteLine (logTxt);
sr.Close();
}
catch
{
//错误处理
}
}
else
{
//文件存在,追加
StreamWriter sr=File.AppendText(logFilePath);
sr.WriteLine (logTxt);
sr.Close();
}
}