However, event messages similar to the following may be logged in the system log:
Event Type: Warning
Source of the event: W3SVC
Event Category: None
Event ID: 1009
Date: 9/28/2005
Time: 3:18:11
PM User: N/A
Computer: IIS-SERVER
describe:
The process serving the application pool "DefaultAppPool" terminated unexpectedly. The process ID is "2548". The process exit code is "0xe0434f4d".
Furthermore, event messages similar to the following may be logged in the application log:
Event Type: Error
Event source: .NET Runtime 2.0 Error Report
Event Category: None
Event ID: 5000
Date: 9/28/2005
Time: 3:18:02 PM
User: N/A
Computer: IIS-SERVER
describe:
EventType clr20r3, P1 , P2 6.0.3790.1830, P3 42435be1, P4 app_web_7437ep-9, P5 0.0.0.0, P6 433b1670, P7 9, P8 a, P9 , P10 NIL.
Solution:
Method 1 Modify the source code of the IHttpModule object to record the exception information into the application log. The recorded information will contain the following:
The virtual directory path with an exception
Exception name
information
Stack Trace
To modify the IHttpModule object, follow these steps.
Note: This code will log messages in the application log with event type "Error" and event source "2.0.50727.0". To test a module, you can request a page using the method to invoke a method that throws an unhandled exception.
Place the following code in a file named .
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
namespace WebMonitor {
public class UnhandledExceptionModule: IHttpModule {
static int _unhandledExceptionCount = 0;
static string _sourceName = null;
static object _initLock = new object();
static bool _initialized = false;
public void Init(HttpApplication app) {
// Do this one time for each AppDomain.
if (!_initialized) {
lock (_initLock) {
if (!_initialized) {
string webenginePath = ((), "");
if (!(webenginePath)) {
throw new Exception((,
"Failed to locate at '{0}'. This module requires .NET Framework 2.0.",
webenginePath));
}
FileVersionInfo ver = (webenginePath);
_sourceName = (, " {0}.{1}.{2}.0",
, , );
if (!(_sourceName)) {
throw new Exception((,
"There is no EventLog source named '{0}'. This module requires .NET Framework 2.0.",
_sourceName));
}
+= new UnhandledExceptionEventHandler(OnUnhandledException);
_initialized = true;
}
}
}
}
public void Dispose() {
}
void OnUnhandledException(object o, UnhandledExceptionEventArgs e) {
// Let this occur one time for each AppDomain.
if ((ref _unhandledExceptionCount, 1) != 0)
return;
StringBuilder message = new StringBuilder("\r\n\r\nUnhandledException logged by :\r\n\r\nappId=");
string appId = (string) (".appId");
if (appId != null) {
(appId);
}
Exception currentException = null;
for (currentException = (Exception); currentException != null; currentException = ) {
("\r\n\r\ntype={0}\r\n\r\nmessage={1}\r\n\r\nstack=\r\n{2}\r\n\r\n",
().FullName,
,
);
}
EventLog Log = new EventLog();
= _sourceName;
((), );
}
}
}
Save the file to the following folder:
C:\Program Files\Microsoft Visual Studio 8\VC
Opens the Microsoft Visual Studio 2005 Command Prompt window.
Type -k and press Enter.
Type csc /t:library /r:, /keyfile: and press Enter.
Type /if , and press Enter.
Type ngen install , and press Enter.
Type gacutil /l UnhandledExceptionModule and press Enter to display the strong name of the UnhandledExceptionModule file.
9. Add the following code to the file of the application based on it.
<add name="UnhandledExceptionModule"
type=", <strong name>" />
Method 2 Change the unhandled exception policy back to the default behavior that occurs in .NET Framework 1.1 and .NET Framework 1.0.
Note: We do not recommend that you change the default behavior. If the exception is ignored, the application may leak resources and abandon locking.
To enable this default behavior, add the following code to the file located in the following folder:
%WINDIR%\\Framework\v2.0.50727
<configuration>
<runtime>
<legacyUnhandledExceptionPolicy enabled="true" />
</runtime>
</configuration>
Event Type: Warning
Source of the event: W3SVC
Event Category: None
Event ID: 1009
Date: 9/28/2005
Time: 3:18:11
PM User: N/A
Computer: IIS-SERVER
describe:
The process serving the application pool "DefaultAppPool" terminated unexpectedly. The process ID is "2548". The process exit code is "0xe0434f4d".
Furthermore, event messages similar to the following may be logged in the application log:
Event Type: Error
Event source: .NET Runtime 2.0 Error Report
Event Category: None
Event ID: 5000
Date: 9/28/2005
Time: 3:18:02 PM
User: N/A
Computer: IIS-SERVER
describe:
EventType clr20r3, P1 , P2 6.0.3790.1830, P3 42435be1, P4 app_web_7437ep-9, P5 0.0.0.0, P6 433b1670, P7 9, P8 a, P9 , P10 NIL.
Solution:
Method 1 Modify the source code of the IHttpModule object to record the exception information into the application log. The recorded information will contain the following:
The virtual directory path with an exception
Exception name
information
Stack Trace
To modify the IHttpModule object, follow these steps.
Note: This code will log messages in the application log with event type "Error" and event source "2.0.50727.0". To test a module, you can request a page using the method to invoke a method that throws an unhandled exception.
Place the following code in a file named .
Copy the codeThe code is as follows:
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
namespace WebMonitor {
public class UnhandledExceptionModule: IHttpModule {
static int _unhandledExceptionCount = 0;
static string _sourceName = null;
static object _initLock = new object();
static bool _initialized = false;
public void Init(HttpApplication app) {
// Do this one time for each AppDomain.
if (!_initialized) {
lock (_initLock) {
if (!_initialized) {
string webenginePath = ((), "");
if (!(webenginePath)) {
throw new Exception((,
"Failed to locate at '{0}'. This module requires .NET Framework 2.0.",
webenginePath));
}
FileVersionInfo ver = (webenginePath);
_sourceName = (, " {0}.{1}.{2}.0",
, , );
if (!(_sourceName)) {
throw new Exception((,
"There is no EventLog source named '{0}'. This module requires .NET Framework 2.0.",
_sourceName));
}
+= new UnhandledExceptionEventHandler(OnUnhandledException);
_initialized = true;
}
}
}
}
public void Dispose() {
}
void OnUnhandledException(object o, UnhandledExceptionEventArgs e) {
// Let this occur one time for each AppDomain.
if ((ref _unhandledExceptionCount, 1) != 0)
return;
StringBuilder message = new StringBuilder("\r\n\r\nUnhandledException logged by :\r\n\r\nappId=");
string appId = (string) (".appId");
if (appId != null) {
(appId);
}
Exception currentException = null;
for (currentException = (Exception); currentException != null; currentException = ) {
("\r\n\r\ntype={0}\r\n\r\nmessage={1}\r\n\r\nstack=\r\n{2}\r\n\r\n",
().FullName,
,
);
}
EventLog Log = new EventLog();
= _sourceName;
((), );
}
}
}
Save the file to the following folder:
C:\Program Files\Microsoft Visual Studio 8\VC
Opens the Microsoft Visual Studio 2005 Command Prompt window.
Type -k and press Enter.
Type csc /t:library /r:, /keyfile: and press Enter.
Type /if , and press Enter.
Type ngen install , and press Enter.
Type gacutil /l UnhandledExceptionModule and press Enter to display the strong name of the UnhandledExceptionModule file.
9. Add the following code to the file of the application based on it.
<add name="UnhandledExceptionModule"
type=", <strong name>" />
Method 2 Change the unhandled exception policy back to the default behavior that occurs in .NET Framework 1.1 and .NET Framework 1.0.
Note: We do not recommend that you change the default behavior. If the exception is ignored, the application may leak resources and abandon locking.
To enable this default behavior, add the following code to the file located in the following folder:
Copy the codeThe code is as follows:
%WINDIR%\\Framework\v2.0.50727
<configuration>
<runtime>
<legacyUnhandledExceptionPolicy enabled="true" />
</runtime>
</configuration>