【问题标题】:Xamarin.Forms can't output to console to debugXamarin.Forms 无法输出到控制台进行调试
【发布时间】:2018-06-13 22:42:18
【问题描述】:

如标题所示,我正在尝试通过以 xamarin 形式写入控制台来调试我的程序。我曾多次尝试过 System.Diagnostics.Debug.WriteLine 和 Console.WriteLine,它们都没有我可以在调试输出或设备日志中看到的任何输出。

编辑:

在以下代码的 Visual Studio 调试输出中看不到任何输出。

using CustomRenderer;
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace CarpApp
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MainPage : ContentPage
    {
        private static ILogger logger = DependencyService.Get<ILogManager>().GetLog();

        public MainPage()
        {
            InitializeComponent();
            logger.Trace("Test1");
            System.Diagnostics.Debug.WriteLine("Test2");
        }

        private void OnMessagesTapped(object sender, EventArgs args)
        {
            System.Diagnostics.Debug.WriteLine("Test3");
            Console.WriteLine("Test4");
            logger.Trace("Test5");
        }

        private void OnFindTapped(object sender, EventArgs args)
        {
            Navigation.PushAsync(new MapPage());
        }

        private void OnGetRidTapped(object sender, EventArgs args)
        {
            Navigation.PushAsync(new GetRidPage());
        }
    }

}

【问题讨论】:

  • 你能分享代码示例吗?
  • 抱歉这个琐碎的问题,但是您是在 debug 中而不是在 release 中运行您的应用程序吗?它只适用于 debug
  • 是的,它正在调试中运行,但我觉得它可能很简单。

标签: xamarin xamarin.forms output


【解决方案1】:

作为一种解决方法,您可以将 NLog 日志记录添加到您的应用程序中(有关详细信息,请参阅 This link)。 除了 FileTarget 日志之外,您还可以定义直接进入控制台的 DebuggerTarget。

【讨论】:

  • 感谢您的回复,但这似乎没有奏效。对于添加到原始帖子的代码,我看不到控制台的输出。我正在使用 Visual Studio 并查看 Debug 的输出。
  • 我以编程方式创建目标:#if DEBUG LoggingRule debugrule = new LoggingRule("", LogLevel.Trace, fileTarget); config.LoggingRules.Add(debugrule); LoggingRule rule2 = new LoggingRule("", LogLevel.Trace, new DebuggerTarget()); config.LoggingRules.Add(rule2); #else LoggingRule loggingrule = new LoggingRule("*", LogLevel.Trace, fileTarget); config.LoggingRules.Add(loggingrule); LogManager.Configuration = 配置;
【解决方案2】:

我终于解决了这个问题,问题是整个项目中有一堆搞砸的命名。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-09
    • 2020-04-20
    • 1970-01-01
    • 2011-12-06
    相关资源
    最近更新 更多