How to collect application logs in Windows Phone 8.1?

I am new to the Windows Phone platform. Is there anything available like logcat in android for windows to collect logs? Thanks in advance.

+5
source share
2 answers

Windows 8.1 introduced new classes to simplify logging. These classes are LoggingChannel , LoggingSession, and others .

Here is an example:

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

I highly recommend watching to make your Windows Store apps more reliable during the 2013 construction conference, where Harry Pearson demonstrates these new APIs in more detail (including uploading a log file to a server server using a background task that runs when the phone is connected to AC power).

+6
source

You can use System.Diagnostics.Debug to view the logs in the Visual Studio console window, but you won’t be able to collect them later because it is displayed only during debugging.

I recommend using MetroLog, a lightweight logging system designed specifically for the Windows Store and Windows Phone applications.

You can install it using NuGet

 Install-Package MetroLog 

Here is an example:

 using MetroLog; using MetroLog.Targets; LogManagerFactory.DefaultConfiguration.AddTarget(LogLevel.Trace, LogLevel.Fatal, new FileStreamingTarget()); GlobalCrashHandler.Configure(); ILogger log = LogManagerFactory.DefaultLogManager.GetLogger<MainPage>(); log.Trace("This is a trace message."); 

You can find a tutorial explaining how to add it to your project at http://talkitbr.com/2015/06/11/adicionando-logs-em-universal-apps . There is also an explanation regarding the extraction of these logs.

0
source

Source: https://habr.com/ru/post/1207367/


All Articles