我尝试使用这些参考链接来实现 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/
答案 0 :(得分:1)
我已将VS2017更新为15.9.11,此问题已通过更新VS2017修复。