How to log errors through MSMQ using Logger ?

Topics: Exception Handling Application Block, Logging Application Block
Jul 22, 2013 at 12:52 PM
Hi

I have custom exception handler written and part of it is supposed to log messages in Text File. I am trying to use Logger class to log messages in MSMQ. I got following error


Thanks in Advance.

Exception Information Details:

Exception Type: System.Messaging.MessageQueueException
MessageQueueErrorCode: UnsupportedFormatNameOperation
Message: The specified format name does not support the requested operation. For example, a direct queue format name cannot be deleted.
ErrorCode: -2147467259
Data: System.Collections.ListDictionaryInternal
TargetSite: Void SendInternal(System.Object, System.Messaging.MessageQueueTransaction, System.Messaging.MessageQueueTransactionType)
HelpLink: NULL
Source: System.Messaging

StackTrace Information Details:

at System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
at System.Messaging.MessageQueue.Send(Object obj, MessageQueueTransactionType transactionType)
at Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.MsmqSendInterface.Send(Message message, MessageQueueTransactionType transactionType)
at Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.MsmqTraceListener.SendMessageToQueue(LogEntry logEntry)
at Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.MsmqTraceListener.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data)
at Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.TraceListenerWrapper.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, TraceEventCache traceEventCache)
at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl.ProcessLog(LogEntry log, TraceEventCache traceEventCache)

Category:

Priority: -1

EventId: 6352

Severity: Error

Title:

Machine: xxxxxxx

App Domain: /LM/W3SVC/1/ROOT/Test.Login.Host-2-130189672514987177

ProcessId: 7964

Process Name: C:\Windows\SysWOW64\inetsrv\w3wp.exe

Thread Name:

Win32 ThreadId:4408

Extended Properties:
Jul 23, 2013 at 7:55 AM
The error you are seeing is MQ_ERROR_UNSUPPORTED_FORMATNAME_OPERATION (0xC00E0020). There is a KB article -- Error 0xC00E0020 Is Generated When You Send Messages By Using the Direct FormatName Property. Are you using encryption or transactions with a remote queue?

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Jul 23, 2013 at 2:25 PM
Hi Randy,


Thanks for Reply. What I am trying to achieve was through Enterprise library I created custom exception handler and one loging handler and wants both of them to work at same time ie. first log message through MSMQ and then executes my custom exception handler. I tried it few different ways


1) I tried logging it through logger class
2) I created two handlers for same exception


I didnt do any encryption and queue is non transactional.

I checked permissions on the queue and my default app pool has full permissions for that particular queue.



Regards,
Jul 26, 2013 at 6:31 AM
The root issue is that you are not able to write to the MSMQ queue though I'm not sure why that is; can you post your configuration?

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Jul 26, 2013 at 12:49 PM
This is my Configuration for enterprise library. XXErrors is Private Queue created with read and write access for application pool. If I just use log policy then it logs it okay but if i go through custom handler and tries to log through logger class , it starts giving the error message etc.



<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
source="Enterprise Library Logging" formatter="Text Formatter"
log="" machineName="." traceOutputOptions="None" />
<add name="Message Queuing Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.MsmqTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.MsmqTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
queuePath=".\Private$\XXErrors" formatter="Binary Log Message Formatter"
traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Timestamp: {timestamp}{newline} Message: {message}{newline} Category: {category}{newline} Priority: {priority}{newline} EventId: {eventid}{newline} Severity: {severity}{newline} Title:{title}{newline} Machine: {localMachine}{newline} App Domain: {localAppDomain}{newline} ProcessId: {localProcessId}{newline} Process Name: {localProcessName}{newline} Thread Name: {threadName}{newline} Win32 ThreadId:{win32ThreadId}{newline} Extended Properties: {dictionary({key} - {value}{newline})}"
name="Text Formatter" />
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.BinaryLogFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Binary Log Message Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Message Queuing Trace Listener" />
</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 Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<exceptionHandling>
<exceptionPolicies>
<add name="BusinessPolicy">
<exceptionTypes>
<add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="ThrowNewException">
<exceptionHandlers>
<add type="Test.Project.ExceptionHandling.CustomHandler.ExceptionHandler, Test.Project.ExceptionHandling.CustomHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
name="ExceptionHandler" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
<add name="WCF Exception Shielding">
<exceptionTypes>
<add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="ThrowNewException">
<exceptionHandlers>
<add type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
faultContractType="GNL.CapitalWorks.Entities.FaultMessage, GNL.CapitalWorks.Entities.Other, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
name="Fault Contract Exception Handler">
<mappings>
<add source="{Guid}" name="Id" />
<add source="{Message}" name="MessageText" />
</mappings>
</add>
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
<add name="DatabasePolicy">
<exceptionTypes>
<add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="NotifyRethrow">
<exceptionHandlers>
<add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
logCategory="General" eventId="100" severity="Error" title="Capital Works"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
priority="0" />
<add type="Test.Project.ExceptionHandling.CustomHandler.ExceptionHandler, Test.Project.ExceptionHandling.CustomHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
name="ExceptionHandler" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
<add name="LogPolicy">
<exceptionTypes>
<add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="ThrowNewException">
<exceptionHandlers>
<add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
priority="0" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>