I redirected System.Diagnostic.Trace and System.Diagnostic.TraceSource to Common.Logging. In the application itself Common.Logging was used. Output is sent to Log4Net (Log4NetLoggerFactoryAdapter), During debugging, I am using LocationInfo (name of class, linenumber, methods, file name). This information is wrong.
I tried to figure out different cases which leads to different error behaviour:
1) Logging via Common.Logging
LOG.Debug("*** Logging via common.logging");
In Common.Logging.Log4Net.Log4NetLogger the static variable declaringType is set to typeof(Log4NetLogger)
To display the correct source information when logging with Common.Logging, it should be typeof(AbstractLogger)
2) Logging via TraceSource
traceSource.TraceData(TraceEventType.Information, 1, "*** Logging via TraceSource");
To display the correct source information when logging with TraceSource, the static variable declaringType in Common.Logging.Log4Net.Log4NetLogger should be typeof(System.Diagnostics.TraceSource)
3) Logging via Trace
Trace.TraceInformation("*** Logging via Trace");
To display the correct source information when logging with Trace, the static variable declaringType in Common.Logging.Log4Net.Log4NetLogger should be typeof(System.Diagnostics.Trace)
So for different Sources (or logger) the declaringType of the class Common.Logging.Log4Net.Log4NetLogger should be adapted.
The default value in my opionion should be AbstractLogger. For Trace and TraceSource only one logger is instantiated in CommonLoggingTraceListener, therefore this special instance should be handled seperately.
I don't know how to distinguish between Trace and TraceSource, because both use the same listener.
In the attachment you will find a sample.
Sample für Fehlerbild
Different settings (declaring type) tested, R means correct, F means wrong behaviour.
Common.Logging.Log4Net.Log4NetLogger
private readonly static Type declaringType = typeof(XXX);
With declaringType set to Common.Logging.Factory.AbstractLogger:
private readonly static Type declaringType = typeof(AbstractLogger);
R corba.at.TraceSourceTest.Program.Main(C:\Work\Projekte\dot.net\TraceSource\Log4net\Program.cs:32) - *** Logging via log4net!
R corba.at.TraceSourceTest.Program.Main(C:\Work\Projekte\dot.net\TraceSource\Log4net\Program.cs:35) - *** Logging via common.logging
F Common.Logging.Simple.CommonLoggingTraceListener.Log(C:\Work\Projekte\dot.net\Commons.Logging\modules\Common.Logging\src\Common\Common.Logging\Logging\Simple\CommonLoggingTraceListener.cs:194) - *** Logging via TraceSource - at
F Common.Logging.Simple.CommonLoggingTraceListener.Log(C:\Work\Projekte\dot.net\Commons.Logging\modules\Common.Logging\src\Common\Common.Logging\Logging\Simple\CommonLoggingTraceListener.cs:194) - *** Logging via TraceSource - at.corba
F Common.Logging.Simple.CommonLoggingTraceListener.Log(C:\Work\Projekte\dot.net\Commons.Logging\modules\Common.Logging\src\Common\Common.Logging\Logging\Simple\CommonLoggingTraceListener.cs:194) - *** Logging via Trace
Original (declaringType is Common.Logging.Log4Net.Log4NetLogger):
private readonly static Type declaringType = typeof(Log4NetLogger);
R corba.at.TraceSourceTest.Program.Main(C:\Work\Projekte\dot.net\TraceSource\Log4net\Program.cs:32) - *** Logging via log4net!
F Common.Logging.Factory.AbstractLogger.Debug(C:\Work\Projekte\dot.net\Commons.Logging\modules\Common.Logging\src\Common\Common.Logging\Logging\Factory\AbstractLogger.cs:338) - *** Logging via common.logging
F Common.Logging.Factory.AbstractLogger.InfoFormat(C:\Work\Projekte\dot.net\Commons.Logging\modules\Common.Logging\src\Common\Common.Logging\Logging\Factory\AbstractLogger.cs:522) - *** Logging via TraceSource - at
F Common.Logging.Factory.AbstractLogger.InfoFormat(C:\Work\Projekte\dot.net\Commons.Logging\modules\Common.Logging\src\Common\Common.Logging\Logging\Factory\AbstractLogger.cs:522) - *** Logging via TraceSource - at.corba
F Common.Logging.Factory.AbstractLogger.InfoFormat(C:\Work\Projekte\dot.net\Commons.Logging\modules\Common.Logging\src\Common\Common.Logging\Logging\Factory\AbstractLogger.cs:522) - *** Logging via Trace
With declaringType set to System.Diagnostics.TraceSource:
private readonly static Type declaringType = typeof(System.Diagnostics.TraceSource);
R corba.at.TraceSourceTest.Program.Main(C:\Work\Projekte\dot.net\TraceSource\Log4net\Program.cs:32) - *** Logging via log4net!
F ? - *** Logging via common.logging
R corba.at.TraceSourceTest.Program.Main(C:\Work\Projekte\dot.net\TraceSource\Log4net\Program.cs:39) - *** Logging via TraceSource -at
R corba.at.TraceSourceTest.Program.Main(C:\Work\Projekte\dot.net\TraceSource\Log4net\Program.cs:42) - *** Logging via TraceSource - at.corba
F ? - *** Logging via Trace
With declaringType set to System.Diagnostics.Trace:
private readonly static Type declaringType = typeof(System.Diagnostics.Trace);
R corba.at.TraceSourceTest.Program.Main(C:\Work\Projekte\dot.net\TraceSource\Log4net\Program.cs:35) - *** Logging via log4net!
F ? - *** Logging via common.logging
F ? - *** Logging via TraceSource - at
F ? - *** Logging via TraceSource - at.corba
R corba.at.TraceSourceTest.Program.Main(C:\Work\Projekte\dot.net\TraceSource\Log4net\Program.cs:48) - *** Logging via Trace