Сбой NLog на Xamarin с System.MissingMethodException: string.Split (char, System.StringSplitOptions) - PullRequest
0 голосов
/ 15 апреля 2019

Я пытался реализовать 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 }

Ожидаемый результат: запись должна быть записана
Фактический результат: исключение отсутствующего метода

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

1 Ответ

1 голос
/ 18 апреля 2019

Я обновил VS2017 до 15.9.11, проблема исправлена ​​обновлением VS2017.

...