Logging Block Event Log Messages Not Appearing On Production Server

Topics: Exception Handling Application Block, Logging Application Block
Dec 17, 2008 at 7:32 PM
Edited Dec 17, 2008 at 10:12 PM
I went through part of the Webcast, "Taking advantage of Microsoft Enterprise Library 4.0 for Visual Studio" where login events (in a Traffic lights Web app.) were logged in the event log i.e. something like this.

 

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

 

 

If Page.IsValid Then

 

 

If funServerValidation() = True Then

 

 

If UsersDB.GetUserValid(objUser) Then

 

cvInvalidLogin.IsValid =

True : LoginSuccess(txtUsername.Text)

 

FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, chkRemember.Checked)

 

Else

 

cvInvalidLogin.IsValid =

False : LoginError(txtUsername.Text)

 

ViewState(

"intTry") = CType(ViewState("intTry"), Integer) + 1

 

 

End If

 

 

Else

 

Page.Validate()

 

End If

 

 

End If

 

 

End Sub

 


 

Private Sub LoginError(ByVal strUserName As String)

Dim leEntry As New LogEntry()

With leEntry

.Message =

String.Format("User {0} attempted to login but failed.", strUserName)

 

.Severity = TraceEventType.Error

 

End With

leEntry.Categories.Add(

"General")

 

Log(leEntry)

 

End Sub

 

Private Sub LoginSuccess(ByVal strUserName As String 

Dim leEntry As New LogEntry()

 

With leEntry

 

 

.Message =

 

String.Format("User {0} successfully logged in.", strUserName)  

.Priority = 10

.EventId = 100

.Severity = TraceEventType.Information

 

End With

leEntry.Categories.Add(

"General")

 

Log(leEntry)

 

End Sub

 

Private Sub Log(ByVal leEntry As LogEntry)

Logger.Write(leEntry)

 

End Sub

The trouble is that this works and puts an entry in the event log on my development machine, but once published on the production server, no log entries are created.

I have created a great deal of my application using the Data access block, but now want to use the Exception Handling and Logging blocks. I am very new to these 2 blocks and was wondering if there is a common explanation why Event logging stops working after deployment on Windows Server 2003?

The following is the relevant content from my web.config file. 

Thanks very much for any help.


Ed Sansbury


<

 

loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">

 

<

 

listeners>

 

 

<

 

add source="Hotel Booking System" formatter="Text Formatter"

 

 

log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

traceOutputOptions="Timestamp" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

name="Formatted EventLog TraceListener" />

 

</

 

listeners>

 

<

 

formatters>

 

<

 

add template="Timestamp: {timestamp}&#xA;Message: {message}&#xA;Category: {category}&#xA;Priority: {priority}&#xA;EventId: {eventid}&#xA;Severity: {severity}&#xA;Title:{title}&#xA;Machine: {machine}&#xA;Application Domain: {appDomain}&#xA;Process Id: {processId}&#xA;Process Name: {processName}&#xA;Win32 Thread Id: {win32ThreadId}&#xA;Thread Name: {threadName}&#xA;Extended Properties: {dictionary({key} - {value}&#xA;)}"

 

 

 

type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

name="Text Formatter" />

 

</

 

 

 

formatters>

 

<

 

 

 

categorySources>

 

<

 

 

 

add switchValue="All" name="General">

 

<

 

 

 

listeners>

 

<

 

 

 

add name="Formatted EventLog TraceListener" />

 

</

 

 

 

listeners>

 

</

 

 

 

add>

 

</

 

 

 

categorySources>

 

<

 

 

 

specialSources>

 

<

 

 

 

allEvents switchValue="All" name="All Events" />

 

<

 

 

 

notProcessed switchValue="All" name="Unprocessed Category" />

 

<

 

 

 

errors switchValue="All" name="Logging Errors &amp; Warnings">

 

<

 

 

 

listeners>

 

<

 

 

 

add name="Formatted EventLog TraceListener" />

 

</

 

 

 

listeners>

 

</

 

 

 

errors>

 

</

 

 

 

specialSources>

 

</

 

 

 

loggingConfiguration>

 

<

 

 

 

exceptionHandling>

 

<

 

 

 

exceptionPolicies>

 

<

 

 

 

add name="Default">

 

<

 

 

 

exceptionTypes>

 

<

 

 

 

add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

 

 

 

 

 

postHandlingAction="None" name="Exception">

 

<

 

 

 

exceptionHandlers>

 

<

 

 

 

add logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"

 

 

 

 

 

formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

 

 

 

priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

 

 

 

 

 

name="Logging Handler" />

 

</

 

 

 

exceptionHandlers>

 

</

 

 

 

add>

 

</

 

 

 

exceptionTypes>

 

</

 

 

 

add>

 

</

 

 

 

exceptionPolicies>

 

</

 

 

 

exceptionHandling>



Dec 18, 2008 at 2:57 AM
It might be a security-related issue.  Check your permissions, not all users can write to the EventLog. 


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Dec 18, 2008 at 9:46 AM
I guess this might be security related so rather than mess around with permissions (I would like to deploy this to many computers) I think I will try and keep a record in the database. This will be easier for me to report on later.

Thanks for your help Sarah.
Dec 18, 2008 at 10:38 AM
If that's the case, logging to the database would be a better solution then.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Feb 20, 2009 at 4:13 AM
You need to run the batch file, "InstallServices.bat" on the server.  It works on your local machine because this batch file is executed as part of the EntLib installation.

  1. Create a bin folder somewhere on the server.
  2. Copy your entlib assemblies and the "InstallServices.bat" file to that folder.
  3. Run the following at the command prompt.
            InstallServices.bat bin

The batch file is located, by default, at "C:\Program Files\Microsoft Enterprise Library 4.1 - October 2008"

HTH,
An

Feb 20, 2009 at 2:14 PM
Thanks for keeping me informed An.  I am sure that will come in handy in the future...