Logging not logging

Topics: Logging Application Block
Apr 3, 2009 at 10:37 AM
Hello,

I've been attempting to set up Enterprise Library 4.1 logging within a console application. It simply contains the lines Logger.Write("Test") and Logger.Write("2nd test", "Category", 1, 1, TraceEventType.Error).

Executing it appears to do nothing, not even an exception is raised. Nothing is logged to the rolling flat file, event log, or e-mail which have all been configured. I've tried using the Quick Start from the included source code and this works! Does anyone have some ideas? Below is my config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<configSections>
		<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
	</configSections>
	<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
	  defaultCategory="Information" logWarningsWhenNoCategoriesMatch="true">
		<listeners>
			<add toAddress="toaddress@domain.com" fromAddress="fromaddress@domain.com"
			  subjectLineStarter="Alert: " subjectLineEnder="SERVER01"
			  smtpServer="smtpd1" smtpPort="25" formatter="MultiLine Text Formatter"
			  listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
			  traceOutputOptions="Timestamp" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
			  name="Email TraceListener" />
			<add source="Enterprise Library Logging" formatter="MultiLine Text Formatter"
			  log="Application" machineName="." listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
			  traceOutputOptions="Timestamp" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
			  name="Formatted EventLog TraceListener" />
			<add fileName="c:\log\rolling.log" footer="" formatter="SingleLine Text Formatter"
			  header="" rollFileExistsBehavior="Increment" rollInterval="Day"
			  rollSizeKB="0" timeStampPattern="yyyy-MM-dd" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
			  traceOutputOptions="Timestamp" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
			  name="Rolling Flat File Trace Listener" />
		</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=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
			  name="MultiLine Text Formatter" />
			<add template="{timestamp(local)} GMT{tab}{title}{tab}{message}{tab}{category}{tab}{priority}{tab}{eventid}{tab}{severity}{tab}{machine}{tab}{appDomain}{tab}{processId}{tab}{processName}{tab}{win32ThreadId}{tab}{threadName}{tab}{dictionary({key} - {value}{tab})}"
			  type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
			  name="SingleLine Text Formatter" />
		</formatters>
		<categorySources>
			<add switchValue="Error" name="Error">
				<listeners>
					<add name="Email TraceListener" />
					<add name="Formatted EventLog TraceListener" />
					<add name="Rolling Flat File Trace Listener" />
				</listeners>
			</add>
			<add switchValue="Information" name="Information">
				<listeners>
					<add name="Rolling Flat File Trace Listener" />
				</listeners>
			</add>
			<add switchValue="Warning" name="Warning">
				<listeners>
					<add name="Rolling Flat File Trace Listener" />
				</listeners>
			</add>
		</categorySources>
		<specialSources>
			<allEvents switchValue="All" name="All Events" />
			<notProcessed switchValue="All" name="Unprocessed Category" />
			<errors switchValue="All" name="Logging Errors &amp; Warnings" />
		</specialSources>
	</loggingConfiguration>
</configuration>

Thanks for any help that can be provided!

Alex Angas.
Apr 3, 2009 at 10:48 AM
Edited Apr 3, 2009 at 10:50 AM
I honestly have no idea as of the moment what's wrong with your config. Are you sure there aren't any enterprise library logs in the event log?   You said you tried it in the quickstart, meaning you used this config in place of the existing configuration included there?
If so, it should have thrown an exception because of mismatched assemblies.  Unless you changed the config in order to reference the unsigned ones?  Is this the case?


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Apr 3, 2009 at 1:57 PM
Hi Sarah,

I worked backwards from the Quick Start config and added in the configuration I needed. There are some subtle differences and no doubt one of those is why my config didn't work. Unfortunately I don't have the patience to work out which one of those it is.

In any case, thanks for your help!

Alex Angas.
Apr 3, 2009 at 3:04 PM
Hi,

Actually I do appear to have found a problem. It appears that if the Email TraceListener fails, then either:
  • logging for the other trace listeners in the same category source doesn't occur at all (with no error), or;
  • an exception shows in the event log describing the failure in the Email TraceListener and other trace listeners in the same category source do not log at all
The exception that displayed in the event log follows:


Timestamp: 03/04/2009 15:55:26
Message: Tracing to LogSource 'General' failed. Processing for other sources will continue. See summary information below for more information. Should this problem persist, stop the service and check the configuration file(s) for possible error(s) in the configuration of the categories and sinks.


Summary for Enterprise Library Distributor Service:
======================================
-->
Message:
Timestamp: 03/04/2009 14:55:26
Message: 4th test
Category: General
Priority: 0
EventId: 667
Severity: Information
Title:
Machine: MACHINENAME
App Domain: SPTestApp.vshost.exe
ProcessId: 6832
Process Name: C:\Projects\SPTestApp\bin\Debug\SPTestApp.vshost.exe
Thread Name:
Win32 ThreadId:6908
Extended Properties:
--> MachineName: MACHINENAME
--> TimeStamp: 03/04/2009 14:55:26
--> FullName: Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
--> AppDomainName: SPTestApp.vshost.exe
--> WindowsIdentity: DOMAIN\angasa

Exception Information Details:
======================================
Exception Type: System.Net.Mail.SmtpFailedRecipientException
FailedRecipient: <toaddress@somedomain.com>
StatusCode: MailboxUnavailable
Message: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for toaddress@somedomain.com
Data: System.Collections.ListDictionaryInternal
TargetSite: System.Net.Mail.MailWriter SendMail(System.Net.Mail.MailAddress, System.Net.Mail.MailAddressCollection, System.String, System.Net.Mail.SmtpFailedRecipientException ByRef)
HelpLink: NULL
Source: System

StackTrace Information Details:
======================================
   at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailMessage.SendMessage(MailMessage message)
   at Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailMessage.Send()
   at Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data)
   at Microsoft.Practices.EnterpriseLibrary.Logging.LogSource.TraceData(TraceEventType eventType, Int32 id, LogEntry logEntry, TraceListenerFilter traceListenerFilter)
   at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter.ProcessLog(LogEntry log)
Severity: Error
Machine: MACHINENAME
Application Domain: SPTestApp.vshost.exe
Process Id: 6832
Process Name: C:\Projects\SPTestApp\bin\Debug\SPTestApp.vshost.exe
Win32 Thread Id: 6908


Hope this helps,

Alex Angas.

Apr 7, 2009 at 11:27 AM
Hi,

Going back to your config, I tried it (Windows Server 2003), and your first log <Logger.Write("Test")> seem to have a success on the rolling flat file. However, I encounter before that i can't seem to log in a flat file because i dont have permission on a certain directory(That happenned when in a windows server 2008), so the workaround there is to grant permission to everyone on the directory where the log file is written. Your second log <Logger.Write("2nd test", "Category", 1, 1, TraceEventType.Error)> will not work, because you've specify a category named "Category" which does not exist your config.
On your last post, it seem that the specified mailing address to where your email trace listener will send the log is seems to be invalid or unavailable.try setting a valid mailing address to send to. Also configure your SMTP server if you need to.

Valiant Dudan
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com


Apr 20, 2009 at 4:19 PM
Thank you, I appear to have this all working now.