I am working on a UWP based application for Windows 10 IoT and I am wanting to configure ETW Tracing so I can view logging remotely using the integrated web interface:
I believe I have created the necessary types, however I cannot see my provider in any of the lists shown within the IoT ETW section:
My EventListener implementation is:
sealed class StorageFileEventListener : EventListener
{
/// <summary>
/// Storage file to be used to write logs
/// </summary>
private StorageFile _mStorageFile = null;
/// <summary>
/// Name of the current event listener
/// </summary>
private readonly string _mName;
public StorageFileEventListener(string name)
{
_mName = name;
Debug.WriteLine("StorageFileEventListener for {0} has name {1}", GetHashCode(), name);
AssignLocalFile();
}
private async void AssignLocalFile()
{
_mStorageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(_mName.Replace(" ", "_") + ".log",
CreationCollisionOption.OpenIfExists);
}
private async void WriteToFile(IEnumerable<string> lines)
{
// TODO:
}
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
// TODO:
}
protected override void OnEventSourceCreated(EventSource eventSource)
{
// TODO:
}
}
My EventSource implementation is:
internal sealed class Logger : EventSource
{
public static Logger Log = new Logger();
[Event(1, Level = EventLevel.Verbose)]
public void Debug(string message, Exception exception)
{
var exceptionMessage = GenerateExceptionMessage(exception);
WriteEvent(1, message + exceptionMessage);
}
[Event(2, Level = EventLevel.Informational)]
public void Info(string message, Exception exception)
{
var exceptionMessage = GenerateExceptionMessage(exception);
WriteEvent(2, message + exceptionMessage);
}
[Event(3, Level = EventLevel.Warning)]
public void Warn(string message, Exception exception)
{
var exceptionMessage = GenerateExceptionMessage(exception);
WriteEvent(3, message + exceptionMessage);
}
[Event(4, Level = EventLevel.Error)]
public void Error(string message, Exception exception)
{
var exceptionMessage = GenerateExceptionMessage(exception);
WriteEvent(4, message + exceptionMessage);
}
[Event(5, Level = EventLevel.Critical)]
public void Critical(string message, Exception exception)
{
var exceptionMessage = GenerateExceptionMessage(exception);
WriteEvent(5, message + exceptionMessage);
}
private static string GenerateExceptionMessage(Exception exception)
{
return exception != null ? $" Exception message - {exception.Message} :: InnerException - {exception.InnerException} :: StackTrace - {exception.StackTrace}"
: "";
}
}
Finally, I initialise and configure my EventSource/EventListener types like so:
EventListener genericListener = new StorageFileEventListener("MyIoTListener");
genericListener.EnableEvents(Logger.Log, EventLevel.Critical);
Am I missing a fundamental step?
This is not a solution for making the source appear on the custom provider list, but does provide access to the events from the web interface. Just type in the GUID of the EventSource into the custom providers text box.
On the phone, I have a C# UWP app with the following event source, (copied from here)
[EventSource(Guid = "{GUID of EventSource}", Name = "SourceName")]
class MyEventSource : EventSource
{
public void MyEvent(string msg, int id) { WriteEvent(1, msg, id); }
public static MyEventSource Log = new MyEventSource();
}
I'm using the Windows Device Portal API (described here), and use the following process in my desktop app to read events:
This all works well and good, however, when I query http://127.0.0.1:10080/api/etw/customproviders, the list is still empty.
On the desktop platform I understand one uses wevtutil.exe:
wevtutil.exe im {App-Manifest}.man
for a similar purpose, but don't know if it applies to windows mobile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With