Pass ILoggerFactory to Unobtanium ProxyServer for internal logging#1448
Pass ILoggerFactory to Unobtanium ProxyServer for internal logging#1448garrytrinder merged 6 commits intomainfrom
Conversation
Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
…lper and remove shell scripts
b457356 to
a872516
Compare
Additional changes: macOS certificate trust rewriteAfter exposing Unobtanium's logs, we noticed the following errors on every startup on macOS: This was always happening but was invisible because Unobtanium's logs weren't surfaced. Root causeUnobtanium's Previously, this error was silently swallowed. The actual macOS certificate trust was handled by two bash scripts ( Fix
|
There was a problem hiding this comment.
Pull request overview
This PR enables Unobtanium's internal logging by passing ILoggerFactory to the ProxyServer constructor, making certificate and proxy lifecycle logs visible at Trace level. It also refactors certificate management on macOS by replacing bash scripts with C# implementations.
Changes:
- Refactored ProxyServer initialization from static constructor to lazy thread-safe initialization via
EnsureProxyServerInitialized()method to support ILoggerFactory injection - Replaced trust-cert.sh and remove-cert.sh bash scripts with MacCertificateHelper C# class for better integration and error handling
- Updated ProxyEngine, CertCommand, and ProxyController to inject ILoggerFactory and call
EnsureProxyServerInitialized()before accessing ProxyServer
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| DevProxy/Proxy/ProxyEngine.cs | Added ILoggerFactory injection, implemented thread-safe lazy ProxyServer initialization, replaced bash script call with MacCertificateHelper in FirstRunSetup |
| DevProxy/Proxy/MacCertificateHelper.cs | New helper class for macOS certificate trust/removal operations using /usr/bin/security commands |
| DevProxy/Commands/CertCommand.cs | Added ILoggerFactory injection, updated to use MacCertificateHelper instead of bash scripts |
| DevProxy/ApiControllers/ProxyController.cs | Added ILoggerFactory injection and EnsureProxyServerInitialized call |
| DevProxy/DevProxy.csproj | Removed references to deleted bash scripts |
| DevProxy/trust-cert.sh | Deleted - replaced by MacCertificateHelper.TrustCertificate |
| DevProxy/remove-cert.sh | Deleted - replaced by MacCertificateHelper.RemoveTrustedCertificate |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Unobtanium.Web.Proxy's internal logs (certificate loading, proxy lifecycle) were invisible because ProxyServer was instantiated without a LoggerFactory. This made debugging certificate and proxy initialization issues difficult.
Changes
ProxyEngine: Inject
ILoggerFactoryand pass to ProxyServer constructor via newEnsureProxyServerInitialized()methodCertCommand & ProxyController: Inject
ILoggerFactoryand callEnsureProxyServerInitialized()before accessing ProxyServerUnobtanium's internal logs now appear at
--log-level Trace:Fixes #1410
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
aka.ms/home/REDACTED/work/dev-proxy/dev-proxy/DevProxy/bin/Debug/net9.0/devproxy --help(dns block)/home/REDACTED/work/dev-proxy/dev-proxy/DevProxy/bin/Debug/net9.0/devproxy --log-level Debug --urls-to-watch REDACTED*(dns block)/home/REDACTED/work/dev-proxy/dev-proxy/DevProxy/bin/Debug/net9.0/devproxy cert ensure --log-level Trace(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.