在 Xamarin.Android 上使用 NLog 时出现 MissingMethodException

MissingMethodException when using NLog on Xamarin.Android

我正在尝试在我的 Xamarin.Android 项目中使用 NLog。当我调用 LogManager.GetCurrentClassLogger() 时它抛出一个 MissingMethodException.

System.MissingMethodException: Method 'StringBuilder.AppendFormat' not found.
   at NLog.LogFactory.GetLogger (NLog.LoggerCacheKey cacheKey) [0x0013a] in <filename unknown>:0 
   at NLog.LogFactory.GetLogger (System.String name) [0x00011] in <filename unknown>:0 
   at NLog.LogManager.GetCurrentClassLogger () [0x0000a] in <filename unknown>:0 

我所做的就是将 NLog nuget 包(版本 4.3.8)添加到我的项目并将以下代码行添加到我的 Application class:

private static readonly Logger log = LogManager.GetCurrentClassLogger();

我对一个新的空白 Xamarin.Android 应用程序执行了相同的步骤并得到了相同的结果。但是,当我对一个新的空白 WPF 应用程序执行相同的操作时,它按预期工作,所以我认为这是 Xamarin.Android 平台特有的问题。

如果有人在这里遇到类似问题,我可以通过简单地更新 Xamarin 来解决这个问题。