我是Windows手机平台的新手.有什么可用的东西像android中的logcat用于收集日志吗?提前感谢.
Windows 8.1引入了新类来简化日志记录.这些类是LoggingChannel,LoggingSession和他人.
这是一个例子:
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);
}
Run Code Online (Sandbox Code Playgroud)
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);
}
Run Code Online (Sandbox Code Playgroud)
我强烈建议在2013年建立会议期间观看让您的Windows应用商店应用程序更可靠的主题演讲,其中Harry Pierson更详细地演示这些新API(包括使用后台任务将日志文件上传到后端服务器,该任务在手机启动时执行连接到交流电源).
| 归档时间: |
|
| 查看次数: |
3398 次 |
| 最近记录: |