Why is System Diagnostics Trace Listener not using formater?

Topics: Logging Application Block
Jul 2, 2011 at 11:35 AM

Hello,

Summarized
Can you please help me understanding how to customize the output of this type of listner (there is no way to customize text formatter)?

In detail

Right now in my code I have sprinkled on a lot of places calls to Debug.WriteLine(“….”).
The calls are omitted in release build and they fit nice with DbgView.,

The downside of this approach is also the fact that they are omitted in release build, because sometimes you want to turn on diagnostics for a short time to get info on production defects etc.

 That’s why I refactored my code and replaced all the Debug.WriteLine() calls with something like this

ServiceLocator.Current.GetInstance<LogWriter>().Write(string.Format("..."));

configure System Diagnostics Trace Listner to be used with System.Diagnostics.DefaultTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

The result I got was the same: Output window and DbgView showing the data as old code did but in format I believe to match standard TextFormatter

Bootstrap Information: 1 : Timestamp: 7/2/2011 10:29:23 AM
Message: IOC ==> Registering in IoC component mapping of Framework.Prism.Services.IRegionOperations as #2 mapping
Category: Bootstrap
Priority: 0
EventId: 1
Severity: Information
Title:
Machine: NIVA-PC
App Domain: Atlas.Client.Shell.vshost.exe
ProcessId: 5420
Process Name: C:\build\debug\Atlas.Client.Shell.vshost.exe
Thread Name:
Win32 ThreadId:8180
Extended Properties:
DateTime=2011-07-02T10:29:23.8252716Z

 

 

 

 

What I need is to (the same I did before EntLib) output only the message text but (to my surprise) it looks like there is no way from Fluent API and configuration tool to set the text formatter to be used with System Diagnostics Trace Listner.

Thanks,
Nikola

Jul 4, 2011 at 3:31 AM

Hi,

You need to create a custom trace listener and format your message there, then use it as the Type Name of your System Diagnostics Trace Listener.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com