Nlog: Some layout renderers not working in xamarin forms

Created on 15 Oct 2019  路  1Comment  路  Source: NLog/NLog

NLog version: 4.6.7

Platform: Xamarin forms

Current NLog config (xml or C#, if relevant)
```c#
public NLogManager()
{
var config = new LoggingConfiguration();

        var consoleTarget = new ConsoleTarget();
        consoleTarget.Layout = "${longdate}|${level:uppercase=true}|{callsite:filename=true}|{exception:format=type}|{exception:format=message}|${exception:format=stackTrace}|${exception:format=:innerFormat=ShortType,Message,Method:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}|${message}";
        config.AddTarget("console", consoleTarget);

        var consoleRule = new LoggingRule("*", LogLevel.Trace, consoleTarget);
        config.LoggingRules.Add(consoleRule);

        var logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Logging");
        if (!Directory.Exists(logDir))
        {
            Directory.CreateDirectory(logDir);
        }

        var fileTarget = new FileTarget();
        fileTarget.FileName = Path.Combine(logDir, "EpochFieldLog.txt");
        fileTarget.Layout = "${longdate}|${level:uppercase=true}|{callsite:filename=true}|{exception:format=type}|{exception:format=message}|${exception:format=stackTrace}|${exception:format=:innerFormat=ShortType,Message,Method:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}|{Gene}${message}";
        config.AddTarget("file", fileTarget);

        var fileRule = new LoggingRule("*", LogLevel.Trace, fileTarget);
        config.LoggingRules.Add(fileRule);

        LogManager.Configuration = config;
    }
- What is the current result? 
some of the layouts that work in my WPF project aren't working in Xamarin forms.

2019-10-15 16:13:08.1440|TRACE|{callsite:filename=true}|{exception:format=type}|{exception:format=message}|||Entering App

2019-10-15 16:13:56.4941|FATAL|{callsite:filename=true}|{exception:format=type}|{exception:format=message}| at EFCloud.App..ctor () [0x00025] in C:\Users\gkula\Documents\Repos\ESG_Products\EpochFieldCloud\EFCloud\EFCloud.Shared\App.xaml.cs:43 ||foobar

- What is the expected result?

2019-10-15 16:13:08.1440|TRACE|Some file name here}|||||Entering App
2019-10-15 16:13:56.4941|FATAL|some name here}|exceptiontypehere|exceptionmessage| at EFCloud.App..ctor () [0x00025] in C:\Users\gkula\Documents\Repos\ESG_Products\EpochFieldCloud\EFCloud\EFCloud.Shared\App.xaml.cs:43 ||foobar
```

  • Did you checked the Internal log?
    Yes
    10-15 16:30:35.134 I/mono-stdout( 2423): 2019-10-15 16:30:34.8639 Info Found 14 configuration items
    2019-10-15 16:30:34.8639 Info Found 14 configuration items
  • Please post full exception details (message, stacktrace, inner exceptions)
  • Are there any workarounds? yes/no
    No
  • Is there a version in which it did work?

  • Can you help us by writing an unit test?

Xamarin question

Most helpful comment

I figured it out. My layout rendnerers were missing "$"

From:
"${longdate}|${level:uppercase=true}|{callsite:filename=true}|{exception:format=type}|{exception:format=message}|${exception:format=stackTrace}|${exception:format=:innerFormat=ShortType,Message,Method:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}|${message}";

To:
"${longdate}|${level:uppercase=true}|${callsite:filename=true}|${exception:format=type}|${exception:format=message}|${exception:format=stackTrace}|${exception:format=:innerFormat=ShortType,Message,Method:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}|${message}";

>All comments

I figured it out. My layout rendnerers were missing "$"

From:
"${longdate}|${level:uppercase=true}|{callsite:filename=true}|{exception:format=type}|{exception:format=message}|${exception:format=stackTrace}|${exception:format=:innerFormat=ShortType,Message,Method:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}|${message}";

To:
"${longdate}|${level:uppercase=true}|${callsite:filename=true}|${exception:format=type}|${exception:format=message}|${exception:format=stackTrace}|${exception:format=:innerFormat=ShortType,Message,Method:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}|${message}";

Was this page helpful?
0 / 5 - 0 ratings

Related issues

imanushin picture imanushin  路  3Comments

ErcinDedeoglu picture ErcinDedeoglu  路  3Comments

vasumsit picture vasumsit  路  3Comments

BobSeu picture BobSeu  路  3Comments

FaMouZx3 picture FaMouZx3  路  3Comments