c# - Xamarin 上的 NLog 因 System.MissingMethodException : string. Split(char,System.StringSplitOptions) 而失败

标签 c# android ios xamarin nlog

我尝试使用这些引用链接来实现 NLog ( https://martynnw.wordpress.com/2016/10/16/logging-with-nlog-in-xamarin-forms/ ) 和 github( https://github.com/Martynnw/AndroidDemos/tree/master/LoggingDemo )

此行遇到此错误 var config = new LoggingConfiguration(); //THIS LINE GENERATING ERROR

[assembly: Dependency(typeof(NLogManager))]
namespace LoggingDemo.Droid
{
    public class NLogManager : ILogManager
    {
        public NLogManager()
        {
            var config = new LoggingConfiguration();   
            var consoleTarget = new ConsoleTarget();
            config.AddTarget("console", consoleTarget);

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

            var fileTarget = new FileTarget();
            string folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            fileTarget.FileName = Path.Combine(folder, "Log.txt");
            config.AddTarget("file", fileTarget);

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

            LogManager.Configuration = config;
        }

        public ILogger GetLog([System.Runtime.CompilerServices.CallerFilePath] string callerFilePath = "")
        {
            string fileName = callerFilePath;

            if (fileName.Contains("/"))
            {
                fileName = fileName.Substring(fileName.LastIndexOf("/", StringComparison.CurrentCultureIgnoreCase) + 1);
            }

            var logger = LogManager.GetLogger(fileName);
            return new NLogLogger(logger);
        }
    }
}

错误:

{NLog.NLogConfigurationException: Error when setting property 'Uppercase' on Layout Renderer: ${uppercase}
---> System.MissingMethodException: string[] string.Split(char,System.StringSplitOptions)
 at NLog.Internal.PropertyHelper.SetPropertyFromString (System.Object obj, System.String propertyName, System.String value,
 NLog.Config.ConfigurationItemFactory configurationItemFactory) [0x000b1] in <b575d0eed9dd4c07998e108d5c7bb2ad>:0
  --- End of inner exception stack trace ---
 at NLog.Internal.PropertyHelper.SetPropertyFromString (System.Object obj, System.String propertyName, System.String value,
 NLog.Config.ConfigurationItemFactory configurationItemFactory) [0x00163] in <b575d0eed9dd4c07998e108d5c7bb2ad>:0
 at NLog.Layouts.LayoutParser.ParseLayoutRenderer (NLog.Config.ConfigurationItemFactory configurationItemFactory,
 NLog.Internal.SimpleStringReader stringReader) [0x00145] in <b575d0eed9dd4c07998e108d5c7bb2ad>:0
 at NLog.Layouts.LayoutParser.CompileLayout (NLog.Config.ConfigurationItemFactory configurationItemFactory,
 NLog.Internal.SimpleStringReader sr, System.Boolean isNested, System.String& text) [0x0007b] in <b575d0eed9dd4c07998e108d5c7bb2ad>:0
 at NLog.Layouts.SimpleLayout.set_Text (System.String value) [0x00024] in <b575d0eed9dd4c07998e108d5c7bb2ad>:0
 at NLog.Layouts.SimpleLayout..ctor (System.String txt, NLog.Config.ConfigurationItemFactory configurationItemFactory) [0x0000d] in <b575d0eed9dd4c07998e108d5c7bb2ad>:0
 at NLog.Layouts.Layout.FromString (System.String layoutText, NLog.Config.ConfigurationItemFactory configurationItemFactory) [0x00000] in <b575d0eed9dd4c07998e108d5c7bb2ad>:0
 at NLog.Layouts.Layout.FromString (System.String layoutText) [0x00006] in <b575d0eed9dd4c07998e108d5c7bb2ad>:0
 at NLog.Layouts.Layout.op_Implicit (System.String text) [0x00000] in <b575d0eed9dd4c07998e108d5c7bb2ad>:0
 at NLog.Targets.TargetWithLayout..ctor () [0x00006] in <b575d0eed9dd4c07998e108d5c7bb2ad>:0
 at NLog.Targets.TargetWithLayoutHeaderAndFooter..ctor () [0x00000] in <b575d0eed9dd4c07998e108d5c7bb2ad>:0
 at NLog.Targets.ConsoleTarget..ctor () [0x00000] in <b575d0eed9dd4c07998e108d5c7bb2ad>:0
 at LogTest.Droid.NLogHelper.NLogManager..ctor () [0x0000f] in AppName\NLogManager.cs:23 }

Expected Result : Log should be written
Actual Result : Missing method exception

IDE: Visual Studio 2017 in Window10

Platform Target Frameworks: XamarinForms (iOS/ Android/ UWP)

Nuget Packages: https://www.nuget.org/packages/NLog/4.6.2/

引用:https://github.com/NLog/NLog/issues/3308

最佳答案

我已将 VS2017 更新到 15.9.11,通过更新 VS2017 解决了问题。

关于c# - Xamarin 上的 NLog 因 System.MissingMethodException : string. Split(char,System.StringSplitOptions) 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55683380/

相关文章:

c# - 打印缩放图像 c#

c# - 'System.ServiceModel.Diagnostics.TraceUtility' 在 WCF 中抛出异常

android - 我如何调试 android 服务 - 扩展服务类的 Activity -

iOS11 视觉框架映射所有面部特征点

ios - 动态改变 UIView 的高度以适应内容

c# - 如何正确格式化字符串?

c# - 处理 WPF 用户控件的事件

android - 单击菜单向右移动屏幕;像 Facebook

android - Google Play 服务 - API 23 已过时

ios - 了解 lipo 工具的架构结果