문제

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