Global. asax
C # code
CopyCode The Code is as follows: <% @ application language = "C #" %>
<% @ Import namespace = "system. Io" %>
<% @ Import namespace = "system. Threading" %>
<SCRIPT runat = "server">
String logpath;
Thread thread;
Void writelog ()
{
While (true)
{
Streamwriter Sw = new streamwriter (logpath, true, encoding. utf8 );
Sw. writeline (thread. Name + ":" + datetime. Now. tostring ());
Sw. Close ();
Thread. currentthread. Join (1000*60); // block for 1 minute
}
}
Void application_start (Object sender, eventargs E)
{
Logpath = httpcontext. Current. server. mappath ("log.txt ");
// In Application
Program Code that runs at startup
Thread = new thread (New threadstart (writelog ));
Thread. Name = "log writing thread ";
Thread. Start ();
}
Void application_end (Object sender, eventargs E)
{
// Code that runs when the application is closed
}
Void application_error (Object sender, eventargs E)
{
// Code that runs when an unhandled error occurs
}
Void session_start (Object sender, eventargs E)
{
// The code that runs when the new session starts
}
Void session_end (Object sender, eventargs E)
{
// The code that runs when the session ends.
// Note: Only the sessionstate mode in the web. config file is set
// The session_end event is triggered only when inproc is used. If the session Mode
// If it is set to StateServer or sqlserver, this event is not triggered.
}
</SCRIPT>