Logging to Eventviewer not working

Topics: Exception Handling Application Block, Logging Application Block
Jun 25, 2007 at 6:40 PM
I'm using the LAP to log exceptions to the eventviewer but when an exception occur it does not get logged to the EV.
Here is how the webconfig in my WCF WebService looks like:

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</configSections>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add source="Enterprise Library Logging" formatter="Text Formatter"
log="" machineName="." listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Event Log Destination" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="Default Category">
<listeners>
<add name="Event Log Destination" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Event Log Destination" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<exceptionHandling>
<exceptionPolicies>
<add name="Log Only Policy">
<exceptionTypes>
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="NotifyRethrow" name="Exception">
<exceptionHandlers>
<add logCategory="Default Category" eventId="100" severity="Error"
title="MyService WCF Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
priority="0" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Logging Handler" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
<system.serviceModel>
<diagnostics wmiProviderEnabled="true" performanceCounters="ServiceOnly">
<messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<bindings>
<wsHttpBinding>
<binding name="NewBinding0" closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="10:10:10" sendTimeout="00:10:00" maxReceivedMessageSize="120000000">
<reliableSession inactivityTimeout="00:20:00" enabled="false" />
<security>
<transport proxyCredentialType="Windows" />
<message establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="MEXGET" name="MyService">
<endpoint binding="wsHttpBinding" bindingConfiguration="NewBinding0" name="wsEndPoint" contract="IMyService" />
<host>
<timeouts closeTimeout="00:01:30" />
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MEXGET">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Microsoft.Transactions.Bridge, Version=3.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="SMDiagnostics, Version=3.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.IdentityModel.Selectors, Version=3.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Web.RegularExpressions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
</compilation>
</system.web>
<appSettings>
</appSettings>
</configuration>

Here is the implementation in MyService.cs :

public DataSet DoSomeWork()
{
try
{
return MyDataAccess.DoSomeWork();
}
catch (Exception ex)
{
ExceptionPolicy.HandleException(ex, Constants.EVENTHANDLERLOG_ONLY);
throw new FaultException<Exception>(ex, new FaultReason(ex.Message), new FaultCode("DomainLayer threw Exception"));
}
}
Jun 26, 2007 at 3:01 AM
vthh50,

When you step into the code in the catch block, do you notice any errors? Are you attempting to do this on your dev box or on a Wn2k3 server?

Cheers,

byronfromwes92
Jun 26, 2007 at 10:05 AM
I have stepped into the code where the exception occurs and and it steppes over the ExceptionPolicy.HandleException(ex, Constants.EVENTHANDLERLOG_ONLY);
so I'm puzzled why it doesnt write anything to the eventviewer. The only thing I get in the EV is
Event Type: Error
Event Source: System.ServiceModel 3.0.0.0
Event Category: WMI
Event ID: 18
Date: 25.06.07
Time: 17:44:15
User: MyComp\ASPNET
Computer: MyComp
Description:
The WMI provider was not registered.
WMI Object: System.ServiceModel.Administration.WbemProvider/4476800
Error:80041003
Process Name: aspnet_wp
Process ID: 5868

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Jun 26, 2007 at 12:41 PM
It's possible that the problem you're having is configuration-related, but as a sanity check you might want to prove that you can manually write to the event log using code similar to that from this article:

http://support.microsoft.com/kb/815314

Also, have you verified that the QuickStart app can successfully log to the event log?


vthh50 wrote:
I have stepped into the code where the exception occurs and and it steppes over the ExceptionPolicy.HandleException(ex, Constants.EVENTHANDLERLOG_ONLY);
so I'm puzzled why it doesnt write anything to the eventviewer. The only thing I get in the EV is
Event Type: Error
Event Source: System.ServiceModel 3.0.0.0
Event Category: WMI
Event ID: 18
Date: 25.06.07
Time: 17:44:15
User: MyComp\ASPNET
Computer: MyComp
Description:
The WMI provider was not registered.
WMI Object: System.ServiceModel.Administration.WbemProvider/4476800
Error:80041003
Process Name: aspnet_wp
Process ID: 5868

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.



Jun 26, 2007 at 2:40 PM
Hi Byron and thanks for the reply.
I've used this successfully from the WCF webservice:
EventLog ev = new EventLog("Application", System.Environment.MachineName, "System.ServiceModel 3.0.0.0");
ev.WriteEntry("Warning is written to system Log", EventLogEntryType.Warning, 10001);
ev.Close();
gonna try the quickstart app but I'm worried that it will work because it will write the log as computer user (Me) but the WCF service writes it as a ASPNET user