Logging/Entlib V3.1 w/Distributor V5.0

Topics: Logging Application Block
Nov 11, 2010 at 3:58 PM

Hi,

We are currently moving all our apps to VS2010 using Entlib 5.0.  The problem is that we have apps using MS Speech Server which it is only supported in VS2005, so I am stuck using Entlib v3.1 for these particular apps.

We need to standardize using the Distributor in V5.  I have tested the following scenarios and they all work well:

Application w/EntLib 5 --> Distributor V5.0

Application w/EntLib 3.1 --> Distributor v3.1

Since the speech server applications are stuck in VS2005 and  EntLib 3.1, we tried the following scenario: Application w/EntLib 3.1 -->Distributor V5.0, wich does not work.  The distributor simply read and discard the messages from MSMQ.  This is the error in the EventLog:

An error occurred in application msmqdistributor.exe in the Enterprise Library Logging Application Block.

Unknwon failure.

The exception that occured was: System.NullReferenceException: Object reference not set to an instance of an object.

at Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter.FormatCategoriesCollection(ICollection`1 categories) in e:\Builds\EntLib\Latest\Source\Blocks\Logging\Src\Logging\Formatters\TextFormatter.cs:line 448

at Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter.<.cctor>b__1(LogEntry le) in e:\Builds\EntLib\Latest\Source\Blocks\Logging\Src\Logging\Formatters\TextFormatter.cs:line 78

at Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.GenericTextFormatter`1.Format(T instance, StringBuilder output) in e:\Builds\EntLib\Latest\Source\Blocks\Logging\Src\Logging\Formatters\GenericTextFormatter.cs:line 193

at Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter.Format(LogEntry log) in e:\Builds\EntLib\Latest\Source\Blocks\Logging\Src\Logging\Formatters\TextFormatter.cs:line 434

at Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry.ToString() in e:\Builds\EntLib\Latest\Source\Blocks\Logging\Src\Logging\LogEntry.cs:line 580

at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)

at System.String.Format(IFormatProvider provider, String format, Object[] args)

at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl.ReportUnknownException(Exception exception, LogEntry log) in e:\Builds\EntLib\Latest\Source\Blocks\Logging\Src\Logging\LogWriterImpl.cs:line 696

I have tried everything I can, I even added the Categories I created in the speech app to the MSMQDistributor.EXE (v5) Configuration (notice that the distributor v3.1 worked without having to create the Categories from the Speech application)

 I debugged the distributor, and what I see is that the category coming from 3.1 is Null (I know there is a category, because when I use the Distributor 3.1, it logs the category).  It throws an exception when attempting to Write (in LogWriterImpl) the log entry:

                     if (log.Categories.Count == 0)  // <<<<<<<<<<<<<<This is null
                    {
                        log.Categories = 
new List<string>(1);
                        log.Categories.Add(structureHolder.DefaultCategory);
                        replacementDone = 
true;
                    }

                    
if (structureHolder.TracingEnabled)
                    {
                        
var logicalOperationStack = GetLogicalOperationStack();
                        AddTracingCategories(log, logicalOperationStack, replacementDone);
                    }

                    
if (ShouldLog(log))
                    {
                        ProcessLog(log, traceEventCache);
                        instrumentationProvider.FireLogEventRaised();
                    }
                }
                
catch (Exception ex)
                {
                    ReportUnknownException(ex, log);     

 

Thanks

Nov 11, 2010 at 6:57 PM

The fundamental issue here is that the MSMQ trace listener and distributor rely on the framework's binary serialization. This format is undocumented and does change from version to version of the .NET framework. The unfortunate result is that the existing code simply isn't going to work in this scenario. 

You can get the scenario you want to work, but you'd need to write a custom trace listener for each version of Entlib that logs to a known format, and then a distributor service that reads that format.

This is probably more work than you want to do right now. If I could ask, what's the underlying scenario you're trying to implement? With more details of what you're trying to do I may be able to come up with another solution.

 

Nov 11, 2010 at 8:07 PM
ctavares wrote:

The fundamental issue here is that the MSMQ trace listener and distributor rely on the framework's binary serialization. This format is undocumented and does change from version to version of the .NET framework. The unfortunate result is that the existing code simply isn't going to work in this scenario. 

You can get the scenario you want to work, but you'd need to write a custom trace listener for each version of Entlib that logs to a known format, and then a distributor service that reads that format.

This is probably more work than you want to do right now. If I could ask, what's the underlying scenario you're trying to implement? With more details of what you're trying to do I may be able to come up with another solution.

 

Thanks for the answer Chris.  It is interesting that I was able to see the message after the Binary fromater massaged the information, but the Category was lost...

Come to think about it, we can have two distributors (3.1 and 5.0) runing side by side.  The speech apps will write to the MSMQ for the 3.1 Distributor while all the other apps can write to the 5.0 Distributor.  At the end of the day both distributors will store the messages in the same DB!

Hopefully the day will come that we can upgrade the speech apps to VS2010 and .Net 4.0

Thanks for your help guys!