NLog: System.ArgumentException: LayoutRenderer cannot be found: 'longdate' when creating new target programatically
Type: Bug
NLog version: 4.3.7 (latest)
Platform: Xamarin Android
Current NLog config
public static void ConfigureAll()
{
LoggingConfiguration config = new LoggingConfiguration();
config = ConfigureConsole(config);
LogManager.Configuration = config;
Debug.Write("Logger linked!");
}
public static LoggingConfiguration ConfigureConsole(LoggingConfiguration config)
{
ConsoleTarget consoleTarget = new ConsoleTarget();
consoleTarget.Name = "Console";
consoleTarget.Layout = @"${date:format=HH\:mm\:ss.fff}|${pad:padding=5:inner=${level:uppercase=true}}|${pad:padding=30:fixedLength=True:inner=${logger}}: ${message}";
LoggingRule rule1 = new LoggingRule("*", Constants.ConsoleLogLevel, consoleTarget);
config.AddTarget("console", consoleTarget);
config.LoggingRules.Add(rule1);
return config;
}
- What is the current result?
– When running the above code, the application throws a
System.ArgumentExceptionon thenew ConsoleTarget();with the message that thelongdateLayoutRenderercannot be found. - What is the expected result? – No exception (obviously)
- Did you checked the Internal log? – No, cannot work out how to do this on Android.
- Please post full exception details (message, stacktrace, inner exceptions)
08-18 16:38:19.120 I/MonoDroid(21457): UNHANDLED EXCEPTION:
08-18 16:38:19.130 I/MonoDroid(21457): System.ArgumentException: LayoutRenderer cannot be found: 'longdate'
08-18 16:38:19.130 I/MonoDroid(21457): at NLog.Config.Factory`2[TBaseType,TAttributeType].CreateInstance (System.String name) [0x0002c] in <filename unknown>:0
08-18 16:38:19.130 I/MonoDroid(21457): at NLog.Layouts.LayoutParser.ParseLayoutRenderer (NLog.Config.ConfigurationItemFactory configurationItemFactory, NLog.Internal.SimpleStringReader sr) [0x00014] in <filename unknown>:0
08-18 16:38:19.130 I/MonoDroid(21457): at NLog.Layouts.LayoutParser.CompileLayout (NLog.Config.ConfigurationItemFactory configurationItemFactory, NLog.Internal.SimpleStringReader sr, Boolean isNested, System.String& text) [0x0009a] in <filename unknown>:0
08-18 16:38:19.130 I/MonoDroid(21457): at NLog.Layouts.SimpleLayout.set_Text (System.String value) [0x00013] in <filename unknown>:0
08-18 16:38:19.130 I/MonoDroid(21457): at NLog.Layouts.SimpleLayout..ctor (System.String txt, NLog.Config.ConfigurationItemFactory configurationItemFactory) [0x0000d] in <filename unknown>:0
08-18 16:38:19.130 I/MonoDroid(21457): at NLog.Layouts.Layout.FromString (System.String layoutText, NLog.Config.ConfigurationItemFactory configurationItemFactory) [0x00000] in <filename unknown>:0
08-18 16:38:19.130 I/MonoDroid(21457): at NLog.Layouts.Layout.FromString (System.String layoutText) [0x00006] in <filename unknown>:0
08-18 16:38:19.130 I/MonoDroid(21457): at NLog.Layouts.Layout.op_Implicit (System.String text) [0x00000] in <filename unknown>:0
08-18 16:38:19.130 I/MonoDroid(21457): at NLog.Targets.TargetWithLayout..ctor () [0x00006] in <filename unknown>:0
08-18 16:38:19.130 I/MonoDroid(21457): at NLog.Targets.TargetWithLayoutHeaderAndFooter..ctor () [0x00000] in <filename unknown>:0
08-18 16:38:19.130 I/MonoDroid(21457): at NLog.Targets.ConsoleTarget..ctor () [0x00000] in <filename unknown>:0
- Are there any work arrounds? – Perhaps using the xml configuration, but I cannot get that to work.
- Is there a version in which it did worked? – I tried 4.3.6 to no avail.
It seems that NLog fails on creating the default ConsoleTarget Layout. The same thing occurs for other Targets, tested with DebuggerTarget.
NLog was installed using NuGet, Xamarin.Forms has version 2.3.1.114.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 27 (18 by maintainers)
While waiting for NLog ver. 4.6 then you can do this:
This will force the AOT-linker to include code even if not referenced directly.