enterprise-librarycontainerstrace-listener

Enterprise Library Logging tracelistener extension issue with resolving ILogFormatter


I have been sitting with a problem for quite a while now and I just can't seem to find what I'm missing. I have written a custom trace listener component for Enterprise Library 5.0 for the Logging application block which works but the configured ILogFormatter just won't resolve and so I always end up with the basic string text when it gets handled by my component. I saw in the enterprise library source code that they use the "Container.ResolvedIfNotNull()" method. It doesn't seem to work for me. I need it to write out a custom formatted string for my component to use. You know, not just the message but the timestamp, machinename, threadId, etc.

Does anyone have any ideas on how to fix this?

Thanks in advance.


Solution

  • Like I've mentioned on this site: http://entlib.codeplex.com/discussions/261749

    When you create your CreationExpression in the TraceListener data class make sure you have a flat constructor definition. To put it in other words, don't return:

    () => new MyTraceListener(new TraceListenerConfig(..., Container.ResolvedIfNotNull<ILogFormatter>(), ...));
    

    just have it in the constructor of the MyTraceListener:

    () => new MyTraceListener(..., Container.ResolvedIfNotNull<ILogFormatter>(), ...);