Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagec#
await deviceInformationService.SubscribeToCurrentBatteryLevel(OnBatteryValueChanged);

private async void OnBatteryValueChanged(DeviceInformationEventArgs args)
{
  string batteryLevel = args.CurrentBatteryLevel.ToString();
}

Custom NLog Target

The VictoR Windows Software Development Kit (SDK) utilizes NLog as it’s logging mechanism. Log info is filtered into Debug, Info, and Warn severity levels. The SDK provides a convenience method to register custom targets to the NLog configuration in order to capture any useful information to a consuming application. A custom target which consumes all levels of the SDK log statements may be created and registered as follows.

Code Block
languagec#
[Target("CustomNlogTarget")]
public sealed class CustomNlogTarget: TargetWithLayout
{
    protected override void Write(LogEventInfo logEvent)
    {
        string message = logEvent.Message;
        //do something with the message here
        ...
    }
}

//NLog.LogLevel.Trace will capture all levels of logging, alternative options are
//Nlog.LogLevel.Debug;
//Nlog.LogLevel.Info;
//Nlog.LogLevel.Warn;
//Nlog.LogLevel.Error;
//Nlog.LogLevel.Fatal;
//Nlog.LogLevel.Off;
DeviceLoggerExtensions.RegisterTarget("CustomNlogTarget", typeof(CustomNlogTarget), NLog.LogLevel.Trace);