Hi, Vlad.
Are you running on IIS5 or IIS6 ?
If you're running on IIS 5.x, the ASP.NET service runs
under the ASPNET account, and that account has to be
granted privileges in order to write to the Event log.
If you're running on IIS 6, the ASP.NET service runs
under the NETWORK SERVICE account, and that
account has to be granted privileges in order to write
to the Event log.
Does your logging work OK when the Application_End
event does occur ? Or does the logging never happen ?
I did a little test, running on IIS 6, to check out if
Application_OnEnd firs when the Application is
forced to end ( and restart ).
Here's something I wrote which works every time
Application_OnEnd fires ( note: *not* Application_End):
First, grant the appropiate account
(ASPNET or NETWORK SERVICE) write permission
on any directory you'd like a text file to be written to,
depending on whether you're running IIS5.x or IIS 6.
Then, test this global.asax, which only has a WriteFile
function in the Application_OnEnd event :
global.asax:
------------
<%@ Application Language="C#"%>
<script runat="server">
protected void Application_OnEnd(Object sender, EventArgs e)
{
WriteFile("Application Ended ");
}
void WriteFile(string strText)
{
System.IO.StreamWriter writer = new System.IO.StreamWriter(@"c:\test.txt",true);
string str;
str = strText + " " + DateTime.Now.ToString( );
writer.WriteLine(str);
writer.Close( );
}
</script>
---------------
Now, open any *.aspx file in the Application, and then open the
global.asax file in notepad and hit enter to move the text in it
one line down and again back up one line, and save the file.
Editing global.asax will force Application_OnEnd to fire.
You should wind up with a text file in whatever directory
you designated in global.asax, with text similar to this :
------------------------------------------------------------
Application Ended 1/11/2005 2:23:51 AM
------------------------------------------------------------
It should work the same for your Event Logging.
If it doesn't, since this does, you could setup a
FileSystemWatcher Console app to do the logging
for you when changes are made to the text file.
See
http://msdn.microsoft.com/library/d.../frlrfSystemIOFileSystemWatcherClassTopic.asp
for sample code to do that.
Just substitute your logging code for this line:
Console::WriteLine(S"File: {0} {1}", e->FullPath, __box(e->ChangeType));
Try it out, and let us know how you do.
Juan T. Llibre
ASP.NET MVP
===========