Reputation: 83
I have a simple C# application that I can run on a windows platform or a linux platform (CentOS 7) using mono 4.2.3.4/832de4b.
When I try to log something using log4Net 2.0.5 on a windows machine I get the following output using a RollingFileAppender:
2016-03-24 09:09:40,374 DEBUG 8 C:\src\Test\Program.cs::20::This is my debug message.
2016-03-24 09:09:40,397 INFO 8 C:\src\Test\Program.cs::21::This is my info message.
2016-03-24 09:09:40,398 WARN 8 C:\src\Test\Program.cs::22::This is my warning message.
2016-03-24 09:09:40,398 FATAL 8 C:\src\Test\Program.cs::23::This is my fatal message.
2016-03-24 09:09:40,399 ERROR 8 C:\src\Test\Program.cs::24::This is my error message.
When I copy this over to a linux box and execute using mono I get the following:
2016-03-24 09:58:58,913 DEBUG 1 ::0::This is my debug message.
2016-03-24 09:58:58,920 INFO 1 ::0::This is my info message.
2016-03-24 09:58:58,920 WARN 1 ::0::This is my warning message.
2016-03-24 09:58:58,923 FATAL 1 ::0::This is my fatal message.
2016-03-24 09:58:58,923 ERROR 1 ::0::This is my error message.
Why am I missing the file name and line numbers from my output? Ideally I would like to have this work with rsyslog but right now I'm trying to get my simple app working correctly.
NOTE: I have a wrapper class around log4net which I have implemented using the information from here.
The RollingFileAppender config looks like this:
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="test_logfile.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="50MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %thread %file::%line::%message%newline" />
</layout>
</appender>
Upvotes: 2
Views: 991
Reputation: 101633
The reason for this is the way log4net gets this information in the first place. I didn't look at source code, but I'm pretty sure it takes this information from stack trace, using something like:
var frame = new System.Diagnostics.StackTrace(true).GetFrame(0);
var filename = frame.GetFileName();
var lineNumber = frame.GetFileLineNumber();
Where runtime gets this information? Usually from debugging symbols which you put near your .dll or .exe files (those .pdb files). Try to not put .pdb file near your exe and run code above - it will return nothing for file name and line number.
Now to mono. First, mono uses another debugging symbols format (.mdb files). If you run on windows also - most likely you did not compile with mono compiler, so you have regular .NET .pdb files. Second - mono will not collect information you want by default, even with correct symbols. You have to pass --debug flag ("mono --debug ").
Summary:
Upvotes: 1