|
1 | | -using System.ComponentModel; |
| 1 | +using System; |
2 | 2 | using System.Diagnostics; |
3 | 3 |
|
4 | | -namespace Renci.SshNet.Abstractions |
| 4 | +namespace Renci.SshNet |
5 | 5 | { |
6 | 6 | /// <summary> |
7 | 7 | /// Provides access to the <see cref="System.Diagnostics"/> internals of SSH.NET. |
8 | 8 | /// </summary> |
9 | | - [EditorBrowsable(EditorBrowsableState.Never)] |
10 | | - public static class DiagnosticAbstraction |
| 9 | + public static class Diagnostics |
11 | 10 | { |
12 | 11 | /// <summary> |
13 | 12 | /// The <see cref="TraceSource"/> instance used by SSH.NET. |
14 | 13 | /// </summary> |
15 | 14 | /// <remarks> |
16 | 15 | /// <para> |
17 | | - /// Currently, the library only traces events when compiled in Debug mode. |
18 | | - /// </para> |
19 | | - /// <para> |
20 | 16 | /// Configuration on .NET Core must be done programmatically, e.g. |
21 | 17 | /// <code> |
22 | | - /// DiagnosticAbstraction.Source.Switch = new SourceSwitch("sourceSwitch", "Verbose"); |
23 | | - /// DiagnosticAbstraction.Source.Listeners.Remove("Default"); |
24 | | - /// DiagnosticAbstraction.Source.Listeners.Add(new ConsoleTraceListener()); |
25 | | - /// DiagnosticAbstraction.Source.Listeners.Add(new TextWriterTraceListener("trace.log")); |
| 18 | + /// Diagnostics.Source.Switch = new SourceSwitch("sourceSwitch", nameof(SourceLevels.Verbose)); |
| 19 | + /// Diagnostics.Source.Listeners.Remove("Default"); |
| 20 | + /// Diagnostics.Source.Listeners.Add(new ConsoleTraceListener()); |
| 21 | + /// Diagnostics.Source.Listeners.Add(new TextWriterTraceListener("SshNetTrace.log")); |
26 | 22 | /// </code> |
27 | 23 | /// </para> |
28 | 24 | /// <para> |
@@ -53,17 +49,19 @@ public static class DiagnosticAbstraction |
53 | 49 | public static readonly TraceSource Source = new TraceSource("SshNet.Logging"); |
54 | 50 |
|
55 | 51 | /// <summary> |
56 | | - /// Logs a message to <see cref="Source"/> at the <see cref="TraceEventType.Verbose"/> |
57 | | - /// level. |
| 52 | + /// Logs a message to <see cref="Source"/> with the specified event type. |
58 | 53 | /// </summary> |
59 | 54 | /// <param name="text">The message to log.</param> |
60 | | - /// <param name="type">The trace event type.</param> |
61 | | - [Conditional("DEBUG")] |
62 | | - public static void Log(string text, TraceEventType type = TraceEventType.Verbose) |
| 55 | + /// <param name="eventType">The trace event type.</param> |
| 56 | + public static void Log(string text, TraceEventType eventType) |
| 57 | + { |
| 58 | + Source.TraceEvent(eventType, Environment.CurrentManagedThreadId, text); |
| 59 | + } |
| 60 | + |
| 61 | + /// <inheritdoc cref="SourceSwitch.ShouldTrace(TraceEventType)" /> |
| 62 | + public static bool IsEnabled(TraceEventType eventType) |
63 | 63 | { |
64 | | - Source.TraceEvent(type, |
65 | | - System.Environment.CurrentManagedThreadId, |
66 | | - text); |
| 64 | + return Source.Switch.ShouldTrace(eventType); |
67 | 65 | } |
68 | 66 | } |
69 | 67 | } |
0 commit comments