Skip to content

Add structured logging infrastructure (#56)#60

Merged
General-Fault merged 6 commits into
mainfrom
feature/56-logging-infrastructure
Jun 8, 2026
Merged

Add structured logging infrastructure (#56)#60
General-Fault merged 6 commits into
mainfrom
feature/56-logging-infrastructure

Conversation

@General-Fault

@General-Fault General-Fault commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

Implements issue #56. Adds a full structured logging pipeline spanning managed code, C++/CLI interop, and the native WebRTC library. Logging is surfaced via \Microsoft.Extensions.Logging.ILoggerFactory\ injected through \Host.SetLoggerFactory(). Debug builds default to a console logger if no factory is provided.

Change Area (required)

  • API-only managed change (\WebRtcNet.Api\ / managed-only behavior)
  • Interop / marshaling / native-boundary change
  • Docs/infra only (no behavior change)

Required Evidence (for behavioral/API changes)

N/A - no behavioral change (logging infrastructure only; no WebRTC or Media Capture behavior is added or altered)

1) W3C reference (required when applicable)

N/A

2) Google source reference (required when applicable)

N/A

3) Intended observable behavior (required when applicable)

N/A

4) Divergence from Google reference (required if diverging)

  • No divergence

Test Evidence (required)

Tests added/updated

  • \WebRtcNet.Api.UnitTests/LoggingInfrastructureTests.cs\ — category mapping resolution, EventId range invariants, \WebRtcLogWriter\ channel forwarding to \ILoggerFactory\ (3 tests)
  • \WebRtcInterop.UnitTests/InteropHResultTests.cpp\ — \InteropHResult::LogIfFailed\ return value for S_OK and E_FAIL (2 Google Test cases)

Commands run + results

  • \dotnet test WebRtcNet.Api.UnitTests\WebRtcNet.Api.UnitTests.csproj
    Passed: 110, Failed: 0 — net10.0-windows and net48
  • \WebRtcInterop.UnitTests\x64\Debug\WebRtcInterop.UnitTests.exe
    All tests passed (Framework x64 Debug)

Change-area test gate confirmation

  • API-only managed change: ran managed NUnit tests
  • Interop/native-boundary change: ran interop unit tests (when environment available)

If environment unavailable (required when checked above)

N/A

Documentation

  • I updated documentation for externally visible behavior changes.
    • \README.md\ — added logging setup section with \Host.SetLoggerFactory\ example
    • \docs/adr/0003-logging-infrastructure.md\ — architecture decision record for logging design choices

Spec/Crosswalk Review (required for W3C-aligned behavior changes)

N/A — logging infrastructure does not affect W3C-aligned API surface

General-Fault and others added 6 commits June 7, 2026 16:50
…ns.Logging package reference

- Document decision to use ILogger DI injection via Host.SetLoggerFactory()
- Define log event structure, category hierarchy, and EventId ranges
- Plan WebRTC log sink with lock-free .NET Channel threading model
- Add Microsoft.Extensions.Logging v9.0.0 to WebRtcNet.Api and WebRtcNet

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add WebRtcLogEventId enum with ranges (WebRTC 1000-1999, Media 2000-2999, Interop 3000-3999)
- Add WebRtcLogEvent record capturing Timestamp, Severity, EventId, Category, ThreadId, Message
- Add LogCategoryMapping class to parse JSON and map WebRTC tags to categories via regex
- Add LogCategoryMapping.json resource with tag-to-category patterns
- Add LoggerFactoryHolder with thread-safe factory holder and default console logger for Debug builds
- Add Host.SetLoggerFactory() public API for apps to inject ILoggerFactory
- Add Microsoft.Extensions.Logging package reference to both WebRtcNet.Api and WebRtcNet

Phase 1 establishes baseline managed logging infrastructure ready for C++/CLI interop bridge.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add IWebRtcLogWriter interface for C++/CLI to call
- Add WebRtcLogWriter with lock-free .NET Channel and background dequeue task
- Logs enqueued from native threads, dequeued to ILogger by category
- Graceful shutdown with channel closure and task timeout
- Add WebRtcLogWriterBridge singleton exposing writer to C++/CLI

Phase 2 establishes thread-safe channel infrastructure ready for C++/CLI log sink.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add MarshalLogging.h with marshal_as specialization for rtc::LoggingSeverity->LogLevel using map
- Add WebRtcLogSink.h/cpp custom rtc::LogSink to capture all WebRTC diagnostics
- OnLogMessage extracts tag, severity, message and forwards to managed writer via channel
- Register log sink with WebRTC in RtcPeerConnectionFactory (eager initialization)
- Add sink to WebRtcInterop.Shared.vcxitems project

Phase 3 completes C++/CLI logging infrastructure; logs now flow from WebRTC → managed ILogger.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Implements #56. Adds ILogger injection via Host.SetLoggerFactory(), a .NET
Channel-backed log writer bridging native WebRTC threads to managed loggers,
a C++/CLI rtc::LogSink capturing WebRTC library diagnostics, and enriched
HRESULT failure logging in MediaDevices.

Managed layer (WebRtcNet.Api):
- WebRtcLogEventId enum with category ranges (WebRTC 1000-1999,
  Media 2000-2999, Interop 3000-3999)
- WebRtcLogEvent record (Timestamp, Severity, EventId, Category,
  ThreadId, Message)
- LogCategoryMapping: JSON resource mapping WebRTC tags to categories
  via regex, loaded from embedded LogCategoryMapping.json
- LoggerFactoryHolder: thread-safe factory holder; Debug builds default
  to console logger, Release builds silent unless configured
- WebRtcLogWriter: Channel + background dequeue task
- WebRtcLogWriterBridge: public bridge exposing WriteInteropLog and
  ResolveWebRtcCategory for C++/CLI callers
- Host.SetLoggerFactory() public API

Interop layer (WebRtcInterop):
- Logging/WebRtcLogSink: rtc::LogSink registered eagerly on
  RtcPeerConnectionFactory creation; uses marshal_as for string
  conversion; routes through WebRtcLogWriterBridge
- Logging/InteropHResult: adds LogIfFailed() alongside ThrowIfFailed();
  formats HRESULT with facility, code, and FormatMessageW system text
- Logging/Marshaling/MarshalLogging.h: removed (severity converted via
  switch in WebRtcLogSink using int passthrough to WriteInteropLog)
- MediaDevices: all COM HRESULT failure points now call LogIfFailed

Tests:
- WebRtcNet.Api.UnitTests/LoggingInfrastructureTests.cs: category
  mapping resolution, EventId ranges, WebRtcLogWriter channel forwarding
- WebRtcInterop.UnitTests/InteropHResultTests.cpp: LogIfFailed return
  value for success and failure HRESULTs

Documentation:
- README: logging setup section with Host.SetLoggerFactory example
- docs/adr/0003-logging-infrastructure.md: architecture decisions
- WebRtcLogEventId: XML doc comments on all enum members

BugzId:56
@General-Fault General-Fault merged commit a3e699e into main Jun 8, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant