Can Enterprise library log to console?

Topics: Logging Application Block
Oct 21, 2011 at 11:55 AM

Hello,

I'm new to Enterprise Library and I've started replacing NLog with EL, I've been able to log to a file but can't find how to log to console (now in my test I'm using Console.WriteLine(xxx);Logger.Write(xxx)

How can I achieve this?

Thanks in advance

Paolo

Oct 21, 2011 at 5:03 PM
Edited Oct 22, 2011 at 4:12 AM

Yes, you can use the System.Diagnostics.ConsoleTraceListener.  

In the configuration tool, go and select Add System Diagnostics Trace Listener.  Then in the properties set the typename to be System.Diagnostics.ConsoleTraceListener
(you can use the selector to drill down to the type).  Just add that listener to your category and you should be good.

In the configuration it will look something like:

 

   <add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.SystemDiagnosticsTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    type="System.Diagnostics.ConsoleTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    name="System Diagnostics Trace Listener" />