Common.Logging for TraceSource

2019-05-11 13:43发布

问题:

I am trying to adopt Common.Logging in our application, however I am having some trouble setting it up with system.diagnostics. It works with straight up Trace, but not TraceSource. I was using Common.Logging.Simple.TraceLoggerFactoryAdapter. Do i need a different adapter for TraceSource?

回答1:

This is pretty late, but maybe it will still help you...

According to the Common.Logging source here, the TraceLoggerFactoryAdapter does support configuring such that it uses TraceSources. The TraceLoggerFactoryAdapter has a property (that is configurable in app.config file) called "useTraceSource". If that is set to "true", it should cause the TraceLoggerFactoryAdapter to dispense TraceLoggers that use a TraceSource internally. Note that according to the Common.Logging documentation here, "useTraceSource" is not documented.

So, you should be able to configure your TraceSources in the System.Diagnostics section of your app.config and tell Common.Logging to use those TraceSources by specifying the TraceLoggerFactoryAdapter and the "useTraceSource" property in the Common.Logging section of the app.config.

Good luck!