سؤال

In Windows Store application I can use:

System.Diagnostics.Debug.WriteLine("Test");

But replacing Debug with Trace gives the following error: CS0103: The name 'Trace' does not exist in the current context How can I fix this?

هل كانت مفيدة؟

المحلول

WinRT doesn't have Trace, and it lacks trace listeners. Debug.WriteLine is the best you can do without resorting to something 3rd party like metrolog.

نصائح أخرى

If your problem is lots of existing code referring to Trace. you could alias Debug as Trace with

using Trace = System.Diagnostics.Debug;

I solved this by setting the Target and Min version respectively to Fall Creators Update (build 16299) and November Update (build 10586). A too early Min version (15063) seems not to contain Trace.

Maybe I misunderstand about UWP/WinRT from the accepted answer that warns about missing trace listeners (maybe it was true at the time of asking/answering). But by nugetting the package System.Diagnostics.TextWriterTraceListener I got a listener that dumps traces into a file.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top