[ 
https://issues.apache.org/jira/browse/LOG4NET-287?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13868352#comment-13868352
 ] 

Daniel Kugel commented on LOG4NET-287:
--------------------------------------

I was able to reproduce this using the following sample app:
(Note that on my Windows 7 x64, Visual Studio 2010, .NET Framework 4.0 the JIT 
won't inline the method if the method is larger than 32 bytes, this might 
differ on other versions of .NET or Windows)
{code}
using System;
using System.Diagnostics;

namespace ConsoleApplication1
{
    class Program
    {
        public static void Method()
        {
            // use ildasm to make sure the method is less than 32 bytes
            Console.WriteLine(new 
StackTrace(true).GetFrame(0).GetFileLineNumber());
        }

        static void Main(string[] args)
        {
            Console.WriteLine("Start: " + new 
StackTrace(true).GetFrame(0).GetFileLineNumber());
            Method();
            Console.WriteLine("End: " + new 
StackTrace(true).GetFrame(0).GetFileLineNumber());
            Console.ReadLine();
        }
    }
}
{code}
And compiling it once with optimization:
{code}csc Program.cs /debug:pdbonly /optimize+{code}
And once without optimization and the above ini file to disable JIT 
optimization:
{code}csc Program.cs /debug:pdbonly /optimize-{code}

So I don't know if its a log4net issue or not but we can explain why it happens 
in .NET regardless of log4net and won't know for sure if its the same with your 
service unless you'll try it.

On another note, I think its a bad idea to rely on line numbers in log messages 
for debugging/troubleshooting because those can change with each version of 
.NET or even with each build of the same target configuration so old logs are 
useless and you might get different line numbers each run. You can't be sure 
what optimizations the compiler and JIT decide to do each time.
You should write the correct text and context to the log to understand where in 
your flow the log was written instead of relying on line numbers.

> Wrong line number for log 
> --------------------------
>
>                 Key: LOG4NET-287
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-287
>             Project: Log4net
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 1.2.10
>         Environment: Windows XP, .NET 3.5, Microsot Virsual Studio
>            Reporter: Shuang yin Liu
>
> In our project, we use the line number function of log4net. Many of log line 
> numbers are 1 line after the actual line. Other are 2 or 3 lines gap(when 
> exception log is written or at the end of the main application).



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to