加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows-phone-8.1 – 如何在Windows Phone 8.1中收集应用程序日

发布时间:2020-12-14 01:57:12 所属栏目:Windows 来源:网络整理
导读:我是 Windows手机平台的新手.有什么可用的东西像android中的logcat用于收集日志吗?提前感谢. 解决方法 Windows 8.1引入了新类来简化日志记录.这些课程分别为 LoggingChannel,LoggingSession和 others. 这是一个例子: App.xaml.cs LoggingSession logSessio
我是 Windows手机平台的新手.有什么可用的东西像android中的logcat用于收集日志吗?提前感谢.

解决方法

Windows 8.1引入了新类来简化日志记录.这些课程分别为 LoggingChannel,LoggingSession和 others.

这是一个例子:

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);
}

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读