The simple and light-weight logging tool for Windows Universal Applications. It inherits some principals which are presented in Windows.Foundation.Diagnostics namespace. In development we used ExGrip.WinRT.Logging solution because of interesting ideas.
- xUnit - unit test framework
First of all you need to have ILoggingSession instance. You may implement your own session object or use WindowsUniversalLogger.Logging.Sessions.LoggingSession as a singleton:
ILoggingSession session = LoggingSession.Instance;
Then you need to instantiate one or several ILoggingChannel objects:
ILoggingChannel channel = new FileLoggingChannel(
"UniqueChannelName",
ApplicationData.Current.LocalFolder,
"logs.txt");
await channel.Init();
session.AddLoggingChannel(channel);
For writing logging message you need to create ILoggingEntry instance:
await LoggingSession.Instance.LogToAllChannels(
new LogEntry(
LogLevel.INFO,
"App is initialized"));
For logging unhandled exceptions you need to open App.xaml.cs and add envent handler for UnhandledException event. Before using in Shared library you need to add reference to WindowsUniversalLogger.Logging library (or install from nuget package) into both of your Win and WP projects Here it's a simple code snippet:
/// ...
using WindowsUniversalLogger.Interfaces;
using WindowsUniversalLogger.Interfaces.Channels;
using WindowsUniversalLogger.Logging;
using WindowsUniversalLogger.Logging.Channels;
using WindowsUniversalLogger.Logging.Sessions;
public sealed partial class App : Application
{
public App()
{
this.InitializeComponent();
this.UnhandledException += OnApplicationUnhandledException;
// ...
}
protected async override void OnLaunched(LaunchActivatedEventArgs e)
{
ILoggingSession session = LoggingSession.Instance;
ILoggingChannel channel = new FileLoggingChannel(
"UniqueChannelName",
ApplicationData.Current.LocalFolder,
"logs.txt");
await channel.Init();
session.AddLoggingChannel(channel);
await LoggingSession.Instance.LogToAllChannels(
new LogEntry(
LogLevel.INFO,
"App is initialized"));
// ...
}
private void OnApplicationUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
LoggingSession.Instance.LogToAllChannels(
new LogEntry(
LogLevel.ERROR,
"Exception: {0}", e.Exception));
e.Handled = true;
}
// ...
}
Read how to run tests with the xUnit.net console runner
Watch at Windows Universal App Logger
WindowsUniversalLogger is licensed under License Apache 2.0 License. Refer to license file for more information.