Custom trace listener or text formatter - assemblies tree is empty

Topics: Logging Application Block
Sep 12, 2012 at 3:10 PM

Hi,

I am following the instructions of how to create custom trace listener for example.

When I open the browser of "custom trace listener", the type selector is empty and display no assemblies - no custom trace listeners are available. That is also the case in adding custom text formatter.

How can I fix this?

Thanks!

Sep 12, 2012 at 3:34 PM

Can you post some sample code of your custom listener or formatter?

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Sep 12, 2012 at 3:44 PM
Edited Sep 12, 2012 at 3:46 PM

Thanks for your quick answer!

I followed the instructions that are written in the enterprise library 5.0 EBOOK:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners;

namespace LoggingApplicationBlockStudy
{
    [ConfigurationElementType(typeof(CustomTraceListenerData))]
    public class TrackingLogTraceListener : CustomTraceListener
    {
        public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
        {
            if (data is LogEntry && this.Formatter != null)
            {
                this.WriteLine(this.Formatter.Format(data as LogEntry));
            }
            else
            {
                this.WriteLine(data.ToString());
            }
        }

        public override void Write(string message)
        {
            this.WriteLine(message);
        }

        public override void WriteLine(string message)
        {
            //Write to custom destination
        }
    }
}

 

 

 

 

 

Sep 12, 2012 at 4:43 PM

Code looks good.  Just build the assembly, then open the config toll, then click Add from File and browse to the assembly and select it.  The TrackingLogTraceListener should appear (once you drill down).

If it's not showing up then it could be that the type is not in the assembly or if the config tool references a different version than the assembly is using (i.e. 5.0.414.0 vs 5.0.505.0).

You could also take a look at the Extensibility Hands-on Labs for Microsoft Enterprise Library 5.0.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Sep 13, 2012 at 7:33 AM

I built the assembly, opened the browser and selected the dll.

After I pressed OPEN, the dll was not opened - nothing happened...

The assemblies tree is empty no metter what I do..

What did I do wrong?

Sep 13, 2012 at 8:10 AM

Can you email me your TraceListener project?  Maybe that will hold a clue?

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Sep 13, 2012 at 8:35 AM

I think I solved it.

"Using namespaceName" statement was missing...

Thanks!