|
1 | | -using System.Diagnostics; |
| 1 | +using System.ComponentModel; |
| 2 | +using System.Diagnostics; |
2 | 3 |
|
3 | 4 | namespace Renci.SshNet.Abstractions |
4 | 5 | { |
5 | | - internal static class DiagnosticAbstraction |
| 6 | + /// <summary> |
| 7 | + /// Provides access to the <see cref="System.Diagnostics"/> internals of SSH.NET. |
| 8 | + /// </summary> |
| 9 | + [EditorBrowsable(EditorBrowsableState.Never)] |
| 10 | + public static class DiagnosticAbstraction |
6 | 11 | { |
7 | | - private static readonly SourceSwitch SourceSwitch = new SourceSwitch("SshNetSwitch"); |
8 | | - |
9 | | - public static bool IsEnabled(TraceEventType traceEventType) |
10 | | - { |
11 | | - return SourceSwitch.ShouldTrace(traceEventType); |
12 | | - } |
13 | | - |
14 | | - private static readonly TraceSource Loggging = |
15 | 12 | #if DEBUG |
16 | | - new TraceSource("SshNet.Logging", SourceLevels.All); |
17 | | -#else |
18 | | - new TraceSource("SshNet.Logging"); |
19 | | -#endif // DEBUG |
| 13 | + /// <summary> |
| 14 | + /// The <see cref="TraceSource"/> instance used by SSH.NET. |
| 15 | + /// </summary> |
| 16 | + /// <remarks> |
| 17 | + /// <para> |
| 18 | + /// Configuration on .NET Core must be done programmatically, e.g. |
| 19 | + /// <code> |
| 20 | + /// DiagnosticAbstraction.Source.Switch = new SourceSwitch("sourceSwitch", "Verbose"); |
| 21 | + /// DiagnosticAbstraction.Source.Listeners.Remove("Default"); |
| 22 | + /// DiagnosticAbstraction.Source.Listeners.Add(new ConsoleTraceListener()); |
| 23 | + /// DiagnosticAbstraction.Source.Listeners.Add(new TextWriterTraceListener("trace.log")); |
| 24 | + /// </code> |
| 25 | + /// </para> |
| 26 | + /// <para> |
| 27 | + /// On .NET Framework, it is possible to configure via App.config, e.g. |
| 28 | + /// <code> |
| 29 | + /// <![CDATA[ |
| 30 | + /// <configuration> |
| 31 | + /// <system.diagnostics> |
| 32 | + /// <trace autoflush="true"/> |
| 33 | + /// <sources> |
| 34 | + /// <source name="SshNet.Logging" switchValue="Verbose"> |
| 35 | + /// <listeners> |
| 36 | + /// <remove name="Default" /> |
| 37 | + /// <add name="console" |
| 38 | + /// type="System.Diagnostics.ConsoleTraceListener" /> |
| 39 | + /// <add name="logFile" |
| 40 | + /// type="System.Diagnostics.TextWriterTraceListener" |
| 41 | + /// initializeData="SshNetTrace.log" /> |
| 42 | + /// </listeners> |
| 43 | + /// </source> |
| 44 | + /// </sources> |
| 45 | + /// </system.diagnostics> |
| 46 | + /// </configuration> |
| 47 | + /// ]]> |
| 48 | + /// </code> |
| 49 | + /// </para> |
| 50 | + /// </remarks> |
| 51 | + public static readonly TraceSource Source = new TraceSource("SshNet.Logging"); |
| 52 | +#endif |
20 | 53 |
|
| 54 | + /// <summary> |
| 55 | + /// Logs a message to <see cref="Source"/> at the <see cref="TraceEventType.Verbose"/> |
| 56 | + /// level. |
| 57 | + /// </summary> |
| 58 | + /// <param name="text">The message to log.</param> |
21 | 59 | [Conditional("DEBUG")] |
22 | 60 | public static void Log(string text) |
23 | 61 | { |
24 | | - Loggging.TraceEvent(TraceEventType.Verbose, |
| 62 | + Source.TraceEvent(TraceEventType.Verbose, |
25 | 63 | System.Environment.CurrentManagedThreadId, |
26 | 64 | text); |
27 | 65 | } |
|
0 commit comments