0

I have a problem with using NLog's callsite with Mono. The line numbers are missing, just like if the debug information file (mdb) was missing. However mdb is not missing. Any ideas what might be wrong?

Some details:

Mono version:

Mono JIT compiler version 3.12.1 (mono-3.12.0-branch/4cb3f77 Fri Jul 24 15:30:03 CST 2015)

NLog version:

4.2.2

C# code:

using NLog;
using NLog.Targets;
using NLog.Config;

namespace TestMono.Verbose
{
    public sealed class TestCallsite
    {
        public static void Main(string[] arguments)
        {
            LoggingConfiguration config = new LoggingConfiguration();

            ConsoleTarget consoleTarget = new ConsoleTarget();
            consoleTarget.Layout = "${message} - ${callsite}";
            config.AddTarget("console", consoleTarget);

            LoggingRule rule1 = new LoggingRule("*", LogLevel.Debug, consoleTarget);
            config.LoggingRules.Add(rule1);

            LogManager.Configuration = config;

            Logger logger = LogManager.GetLogger("Example");
            logger.Trace("trace log message");
            logger.Debug("debug log message");
            logger.Info("info log message");
            logger.Warn("warn log message");
            logger.Error("error log message");
            logger.Fatal("fatal log message");
        }
    }
}

Compilation command:

mcs /reference:NLog /reference:NLog.dll test.cs -debug

Console output:

>mono test.exe
debug log message - TestMono.Verbose.TestCallsite.Main
info log message - TestMono.Verbose.TestCallsite.Main
warn log message - TestMono.Verbose.TestCallsite.Main
error log message - TestMono.Verbose.TestCallsite.Main
fatal log message - TestMono.Verbose.TestCallsite.Main

There should be a line number in bracket after "Main".

Edited:

Console output on windows with .NET:

> .\ConsoleApplication1.exe
debug log message - ConsoleApplication1.TestCallsite.Main(Program.cs:26)
info log message - ConsoleApplication1.TestCallsite.Main(Program.cs:27)
warn log message - ConsoleApplication1.TestCallsite.Main(Program.cs:28)
error log message - ConsoleApplication1.TestCallsite.Main(Program.cs:29)
fatal log message - ConsoleApplication1.TestCallsite.Main(Program.cs:30)
Barbie
  • 11
  • 2
  • I think this is related: http://stackoverflow.com/questions/19252938/cannot-get-stacktrace-source-line-information-from-mono-dll – Julian Jan 09 '16 at 13:14

2 Answers2

1

Use the --debug flag when calling mono:

> mono --debug test.exe
knocte
  • 16,941
  • 11
  • 79
  • 125
  • thanks, but I'm afraid that's not it - the line numbers are still missing. – Barbie Dec 30 '15 at 09:48
  • For my case (using `NLog` with `mono` on macOS), this was it. Adding `{$callsite-linenumber`} was generating only 0, using `--debug` it began emitting the correct line numbers (with the exception of dynamic classes). This answer shouldn't be dismissed if you haven't tried it yet. – Joe Nov 23 '17 at 15:46
0

NLog has a seperate layout render for callsite-linenumber. Not exactly sure why its seperate and not just an option in the callsite layout render https://github.com/NLog/NLog/wiki/Callsite-line-number-layout-renderer

${callsite-linenumber:skipFrames=Integer}

Hope that gives you what you need

Alex Bezek
  • 467
  • 2
  • 7
  • Thanks for the answer. But: 1. callsite-linenumber is already a part of callsite, so there is no need to explicitly call callsite-linenumber if you already have callsite. 2. callsite-linenumber is not working as well for my environment, so I guess for Mono on Linux. 3. callsite is displaying line numbers for the same code ran on windows + .net. I will edit my post with the windows console output to show the diffetence. – Barbie Jan 05 '16 at 11:41
  • I can confirm that both `${callsite}` and `${callsite-linenumber}` use the same code. The latter is a short-cut. – Julian Jan 09 '16 at 13:11