Log the agent conversation through ILogger - #38
Open
darinkes wants to merge 1 commit into
Open
Conversation
SshAgent gets a Logger property (Microsoft.Extensions.Logging .Abstractions, which newer SSH.NET already depends on; default NullLogger). At Trace level every raw protocol message is logged as structured SshAgentTraceMessage state carrying the direction and the complete framed payload: plain text sinks render only the summary line, structured sinks and custom loggers get the raw bytes and choose their own representation. The docs warn that add requests contain private key material. Both send paths now share the same buffered serialize/read helpers, which also gives the sync path the message length validation the async path already had. The sample hex-dumps the traffic with --verbose through a small HexDumpLogger.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wire-level logging for the agent conversation, done the
ILoggerway: the library logs the data, the attached logger owns the representation.SshAgent.Logger(Microsoft.Extensions.Logging.Abstractions, defaultNullLogger.Instance): atTracelevel, every raw protocol message is logged withEventId(1, "AgentMessage").SshAgentTraceMessageis the structured log state: it carriesDirectionand the complete framedData, and implementsIReadOnlyList<KeyValuePair<string, object?>>withDirection/DataLength/Data/{OriginalFormat}properties. Consequences:Request agent message, 128 bytes— no accidental byte dumps in logs,byte[]as a property and apply their own destructuring/redaction,ILoggerpattern-matches the state and renders however it wants — the sample's--verbosedoes exactly that with a ~25-lineHexDumpLogger.Traceis off in every default logging configuration.Microsoft.Extensions.Logging.Abstractions8.0.3 is the exact version SSH.NET 2025.1.0 already depends on, so consumers on newer SSH.NET pay nothing extra; it is netstandard2.0 and works on all four target frameworks.Serialize/ReadMessage/Parsehelpers — as a side effect the sync path gains the message-length validation the async path already had.Sample output of
SshNet.Agent.Sample --pageant --verbose:Stacked on #37 (the sample's
--verbosebuilds on the System.CommandLine parser): merge #37 first; GitHub retargets this PR tomainautomatically when the branch is deleted.Test plan
--verbose— hex dump above, including through the Pageant WM_COPYDATA transport