| | | 1 | | using System.ComponentModel; |
| | | 2 | | using System.Diagnostics; |
| | | 3 | | |
| | | 4 | | namespace Renci.SshNet.Abstractions |
| | | 5 | | { |
| | | 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 |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// The <see cref="TraceSource"/> instance used by SSH.NET. |
| | | 14 | | /// </summary> |
| | | 15 | | /// <remarks> |
| | | 16 | | /// <para> |
| | | 17 | | /// Currently, the library only traces events when compiled in Debug mode. |
| | | 18 | | /// </para> |
| | | 19 | | /// <para> |
| | | 20 | | /// Configuration on .NET Core must be done programmatically, e.g. |
| | | 21 | | /// <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")); |
| | | 26 | | /// </code> |
| | | 27 | | /// </para> |
| | | 28 | | /// <para> |
| | | 29 | | /// On .NET Framework, it is possible to configure via App.config, e.g. |
| | | 30 | | /// <code> |
| | | 31 | | /// <![CDATA[ |
| | | 32 | | /// <configuration> |
| | | 33 | | /// <system.diagnostics> |
| | | 34 | | /// <trace autoflush="true"/> |
| | | 35 | | /// <sources> |
| | | 36 | | /// <source name="SshNet.Logging" switchValue="Verbose"> |
| | | 37 | | /// <listeners> |
| | | 38 | | /// <remove name="Default" /> |
| | | 39 | | /// <add name="console" |
| | | 40 | | /// type="System.Diagnostics.ConsoleTraceListener" /> |
| | | 41 | | /// <add name="logFile" |
| | | 42 | | /// type="System.Diagnostics.TextWriterTraceListener" |
| | | 43 | | /// initializeData="SshNetTrace.log" /> |
| | | 44 | | /// </listeners> |
| | | 45 | | /// </source> |
| | | 46 | | /// </sources> |
| | | 47 | | /// </system.diagnostics> |
| | | 48 | | /// </configuration> |
| | | 49 | | /// ]]> |
| | | 50 | | /// </code> |
| | | 51 | | /// </para> |
| | | 52 | | /// </remarks> |
| | 4 | 53 | | public static readonly TraceSource Source = new TraceSource("SshNet.Logging"); |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Logs a message to <see cref="Source"/> at the <see cref="TraceEventType.Verbose"/> |
| | | 57 | | /// level. |
| | | 58 | | /// </summary> |
| | | 59 | | /// <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) |
| | 136952 | 63 | | { |
| | 136952 | 64 | | Source.TraceEvent(type, |
| | 136952 | 65 | | System.Environment.CurrentManagedThreadId, |
| | 136952 | 66 | | text); |
| | 136952 | 67 | | } |
| | | 68 | | } |
| | | 69 | | } |