0

The ms doc says it should exist a Listeners property in Debug.Diagnostics.Debug in netstandard 2, but this is not the case in a real project. The Listeners property is undefined.

I tryed adding the System.Diagnostics.Debug nuget with no luck.

Any clue?

Softlion
  • 12,281
  • 11
  • 58
  • 88
  • .NETCore does not have this property, that makes it non-standard. As you can tell from [this github page](https://github.com/dotnet/corefx/issues/31003), this is a pretty big obstacle to porting programs and they recently worked on getting this fixed. Whether that means it gets added to a new .netstandard remains to be seen. Do keep in mind that a library ought not mess with listeners, configuring them is a task that belongs to the main app. Always a good idea to mention why you need it so users can propose an alternative. – Hans Passant Dec 19 '18 at 09:06

1 Answers1

3

When you try to navigate to the page for Debug.Listeners Property for .NET Standard 2 the page clearly states:

The requested page is not available for .NET Standard 2.0. You have been redirected to the newest product version this page is available for.

Diving in a bit deeper, you can find all APIs implemented in .NET standard 2 on their github. Here you can see that the public static class Debug doesn't have a Listeners property.

However, the article on the Debug.Listeners Property I referred to above also states

The Listeners collection is shared by both the Debug and the Trace classes; adding a trace listener to either class adds the listener to both.

The .NET standard API's also learns us that the public sealed class Trace does implement public static TraceListenerCollection Listeners { get; }. This would lead me to believe you can access the Listeners through the Trace class.

rickvdbosch
  • 14,105
  • 2
  • 40
  • 53