gpt4 book ai didi

windows-phone-8.1 - 如何在 windows phone 8.1 中收集应用程序日志?

转载 作者:行者123 更新时间:2023-12-04 07:44:21 25 4
gpt4 key购买 nike

我是 windows 手机平台的新手。有没有像 android 中的 logcat 之类的东西可以用来收集日志?提前致谢。

最佳答案

Windows 8.1 引入了新类来简化日志记录。这些类是 LoggingChannel , LoggingSessionothers .

下面是一个例子:

App.xaml.cs

LoggingSession logSession;
LoggingChannel logChannel;

public App()
{
this.InitializeComponent();
this.UnhandledException += App_UnhandledException;
}

void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
logChannel.LogMessage("Unhandled exception: " + e.Message);
logSession.SaveToFileAsync(Windows.Storage.ApplicationData.Current.LocalFolder, "MainLog.log").AsTask().Wait();
}

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
logSession = new LoggingSession("MainLogSession");
Resources["MainLogSession"] = logSession;

logChannel = new LoggingChannel("AppLogChannel");
logSession.AddLoggingChannel(logChannel);
}

MainPage.xaml.cs

LoggingChannel logChannel;

public MainPage()
{
this.InitializeComponent();

var logSession = (LoggingSession)Application.Current.Resources["MainLogSession"];
logChannel = new LoggingChannel("MainPageLogChannel");
logSession.AddLoggingChannel(logChannel);
logChannel.LogMessage("MainPage ctor", LoggingLevel.Information);
}

我强烈建议观看 Making your Windows Store Apps More Reliable在 2013 年构建 session 期间的主题演讲中,Harry Pierson 更详细地演示了这些新 API(包括使用后台任务将日志文件上传到后端服务器,该任务在手机连接到交流电源时执行)。

关于windows-phone-8.1 - 如何在 windows phone 8.1 中收集应用程序日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27055515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com