Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to collect application logs in windows phone 8.1?

I am new to windows phone platform.Is there anything available like logcat in android for windows for collecting logs?Thanks in advance.

like image 559
JINTO JOSE Avatar asked Nov 21 '14 06:11

JINTO JOSE


People also ask

Where do I save application logs?

The AppData directory is usually the best place for log files, however, it depends on the application & the purpose of the files.


1 Answers

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

Here's 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 the Making your Windows Store Apps More Reliable keynote during the 2013 build conference, where Harry Pierson demonstrates these new APIs in more detail (including uploading the log file to a backend server using a background task that gets executed when the phone is connected to AC power).

like image 164
Decade Moon Avatar answered Nov 18 '22 07:11

Decade Moon