mongo-csharp-driver / Logging
AGENTS.md3.2k starsChanged 4 months agoApache-2.0View on GitHub
Bridges the event subsystem (Core/Events/) to Microsoft.Extensions.Logging. When the user supplies a LoggerFactory via MongoClientSettings.LoggingSettings, events are offered to the configured logger as structured log entries; whether each entry is actually emitted depends on the logger's level filter. Every dispatched EventType must have a registered template provider — EventLogger dereferences the provider unconditionally, so a missing provider for a dispatched event throws rather than skipping silently. In practice every event currently dispatched is covered; if you add a new EventType…
Trending
Quiet since September.about the whole repository
Who's talking about mongodb/mongo-csharp-driver
- jbogard/MongoDB.Driver.Core.Extensions.DiagnosticSources“Support for latest MongoDB library with signing”GitHub · Jul 28, 2024 · 13 reactions
- opensearch-project/opensearch-net“[FEATURE] Add LINQ Support to the OpenSearch C# Client”GitHub · Sep 18, 2023 · 5 reactions
- nopSolutions/nopCommerce“MongoDB database support”GitHub · Apr 30, 2019 · 4 reactions
- microsoft/aspire“MongoDB.Driver v3 breaks Aspire.MongoDB.Driver integration”GitHub · Oct 18, 2024 · 3 reactions
- jbogard/MongoDB.Driver.Core.Extensions.DiagnosticSources“Deprecate this package”GitHub · Apr 21, 2026 · 2 reactions
The biggest 5 of 40 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 40
Talked about on GitHub (40 times).
On GitHub · 40
- Jul 28, 2024Support for latest MongoDB library with signing — jbogard/MongoDB.Driver.Core.Extensions.DiagnosticSources13 reactions · 5 comments
- Sep 18, 2023[FEATURE] Add LINQ Support to the OpenSearch C# Client — opensearch-project/opensearch-net5 reactions · 1 comment
- Apr 30, 2019MongoDB database support — nopSolutions/nopCommerce4 reactions · 24 comments
- Oct 18, 2024MongoDB.Driver v3 breaks Aspire.MongoDB.Driver integration — microsoft/aspire3 reactions · 9 comments
- Apr 21, 2026Deprecate this package — jbogard/MongoDB.Driver.Core.Extensions.DiagnosticSources2 reactions · 1 comment
35 more on GitHub
- Nov 5, 2025Corrected Membership Session Handling — OrleansContrib/Orleans.Providers.MongoDB2 reactions · 2 comments
- Jun 4, 2016Support .NET Core — tugberkugurlu/AspNetCore.Identity.MongoDB2 reactions · 1 comment
- Jul 12, 2026Upgrade MongoDB.Driver to 3.9.0 to fix Snappier and SharpCompress vulnerabilities — madelson/DistributedLock1 reaction
- May 28, 2026Upgrade MongoDB.Driver to 3.9.0 — abpframework/abp1 reaction · 1 comment
- May 12, 2026Upgrade MongoDB.Driver to 3.8.1 — abpframework/abp1 reaction
- Mar 19, 2026bump MongoDB.Driver to 3.7.1 — abpframework/abp1 reaction
- Jan 18, 2026Update MongoDB.Driver package version to 3.6.0 — abpframework/abp1 reaction · 1 comment
- Nov 20, 2025Update MongoDB.Driver to version 3.5.1 — abpframework/abp1 reaction
- Jan 30, 2023Hangfire.Mongo is incompatible with the MongoDB.Driver LINQ3 provider — gottscj/Hangfire.Mongo1 reaction · 1 comment
- Jun 6, 2022Mongo Driver Compatibility — alirezanet/Gridify1 reaction · 3 comments
- Mar 31, 2015Support for 2.0 async driver — RobThree/MongoRepository1 reaction · 35 comments
- Sep 29, 2026Bump MongoDB.Driver from 2.11.5 to 2.19.0 — ramonaoldf/run-devops0 reactions
- Sep 15, 2026Bump the nuget group with 1 update — ApurvSinghal/ApurvXam0 reactions
- Aug 2, 2026Bump MongoDB.Driver from 2.8.1 to 2.19.0 — mohaom/TailwindTraders-Website0 reactions
- Jan 12, 2025Bump MongoDB.Driver from 2.14.1 to 2.19.0 in /src/Infrastructure — vigovlugt/LeagueOfItemsBackend0 reactions
- Aug 6, 2024Update dependency MongoDB.Driver to 2.19.0 [SECURITY] — MrDariusAD/DynamicFilter0 reactions
- Aug 6, 2024Update dependency MongoDB.Driver to 2.12.2 [SECURITY] — ShamKarthikS-Hexaware/recicd0 reactions
- Aug 6, 2024Update dependency MongoDB.Driver to 2.12.2 [SECURITY] — MrDariusAD/GirlfriendAdventskalender0 reactions
- Jan 15, 2024Bump MongoDB.Driver.Core and MongoDB.Bson — kravvya/GardenLog.V20230 reactions
- Nov 17, 2023build(deps): bump MongoDb_Version from 2.19.0 to 2.22.0 — AntonioFalcaoJr/EventualShop0 reactions
- Mar 28, 2023Bump MongoDB.Driver from 2.19.0 to 2.19.1 — eincioch/dotnet-microservices-boilerplate0 reactions
- Mar 27, 2023Bump MongoDB.Driver from 2.19.0 to 2.19.1 — niaz-ali-khan/microservise0 reactions
- Mar 3, 2023Bump MongoDB.Driver from 2.13.1 to 2.19.0 in /DotNet/POC/DatabaseBenchmark — AdamNagy/Nadam.Tryouts0 reactions
- Mar 3, 2023Bump MongoDB.Driver from 2.12.3 to 2.19.0 in /Esiur.Stores.MongoDB — esiur/esiur-dotnet0 reactions
- Oct 17, 2022Bump MongoDB.Driver from 2.17.1 to 2.18.0 in /src/backend — ScottishTapWater/OrderBook0 reactions
- Oct 17, 2022fix(deps): bump MongoDB.Driver from 2.16.1 to 2.18.0 — Manu0912/doppler-push-contact0 reactions
- Oct 17, 2022Bump MongoDB.Driver from 2.13.0 to 2.18.0 — uruk-project/uruk-server0 reactions
- Oct 17, 2022Bump MongoDB.Driver from 2.15.1 to 2.18.0 — joelbyford/ApiPatternsClient0 reactions
- Oct 14, 2022Bump MongoDB.Driver from 2.13.1 to 2.18.0 in /examples/AspNetCoreMvc — brucehu123/opentelemetry-dotnet-instrumentation0 reactions
- Oct 14, 2022Bump MongoDB.Driver from 2.12.4 to 2.18.0 in /services/common/Platform.Common — frogsbreath-games/eucre0 reactions
- Oct 14, 2022Bump MongoDB.Driver from 2.12.4 to 2.18.0 in /services/lobby/Platform.Lobby.Tests — frogsbreath-games/eucre0 reactions
- Oct 14, 2022Bump MongoDB.Driver from 2.12.4 to 2.18.0 in /services/eucre-game/Games.Eucre.Api — frogsbreath-games/eucre0 reactions
- Oct 14, 2022Bump MongoDB.Driver from 2.12.4 to 2.18.0 in /services/weather/Weather.Api — frogsbreath-games/eucre0 reactions
- Oct 14, 2022Bump MongoDB.Driver from 2.12.4 to 2.18.0 in /services/library/Platform.Library.Api — frogsbreath-games/eucre0 reactions
- May 24, 2022Bump MongoDB.Driver from 2.13.1 to 2.15.1 in /examples/AspNetCoreMvc — brucehu123/opentelemetry-dotnet-instrumentation0 reactions
In this repository35 other files it gives its agents.
- AGENTS.mdAGENTS.md
- src/MongoDB.Bson/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Authentication/AGENTS.mdAGENTS.md
- src/MongoDB.Driver.Authentication.AWS/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Core/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Core/Bindings/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Core/Events/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Core/Operations/AGENTS.mdAGENTS.md
- src/MongoDB.Driver.Encryption/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Encryption/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/GeoJsonObjectModel/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/GridFS/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Linq/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Search/AGENTS.mdAGENTS.md
- tests/MongoDB.Driver.TestHelpers/AGENTS.mdAGENTS.md
- tests/MongoDB.Driver.Tests/Specifications/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- src/MongoDB.Bson/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver.Authentication.AWS/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Authentication/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Core/Bindings/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Core/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Core/Events/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Core/Logging/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Core/Operations/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver.Encryption/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Encryption/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/GeoJsonObjectModel/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/GridFS/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Linq/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Search/CLAUDE.mdCLAUDE.md
- tests/MongoDB.Driver.TestHelpers/CLAUDE.mdCLAUDE.md
- tests/MongoDB.Driver.Tests/Specifications/CLAUDE.mdCLAUDE.md
The file
Files
Core/Logging — AGENTS.md
Bridges the event subsystem (Core/Events/) to Microsoft.Extensions.Logging. When the user supplies a LoggerFactory via MongoClientSettings.LoggingSettings, events are offered to the configured logger as structured log entries; whether each entry is actually emitted depends on the logger's level filter. Every dispatched EventType must have a registered template provider — EventLogger dereferences the provider unconditionally, so a missing provider for a dispatched event throws rather than skipping silently. In practice every event currently dispatched is covered; if you add a new EventType value, you must also register a template for it in the relevant StructuredLogTemplateProviders*.cs. (LogCategories.Client is the lone non-event sink — top-level driver logs that don't ride on an EventType; do not look for a Client template provider.)
Wiring
User configures via MongoClientSettings.LoggingSettings = new LoggingSettings(loggerFactory, maxDocumentSize). The LoggingSettings type itself lives at src/MongoDB.Driver/Core/Configuration/LoggingSettings.cs and is surfaced through MongoClientSettings.LoggingSettings. It has a single constructor that takes the LoggerFactory plus an optional maxDocumentSize typed Optional<int> (not raw int). Optional<T> defines an implicit conversion from T, so new LoggingSettings(factory, 5000) works directly; Optional.Create(value) is only needed when overload resolution needs disambiguation. The cluster builder propagates LoggingSettings through every component that constructs an EventLogger<T> (server monitors, connection pool, server selection, command path).
Redaction. The wire layer redacts the bodies of an allowlisted set of auth-carrying commands (authenticate, saslStart, saslContinue, getnonce, createUser, updateUser, copydbsaslstart, copydb, plus hello / legacy-hello when carrying speculativeAuthenticate) before the event is published — see Core/Connections/CommandEventHelper.ShouldRedactCommand and the redaction note in Core/Events/AGENTS.md. Anything outside that allowlist is not scrubbed by the logging layer; it only truncates document payloads via MaxDocumentSize. Do not embed application-level secrets (KMS material, X.509 cert bytes, ad-hoc tokens) in arbitrary command payloads or log scopes — they will pass through unredacted into whichever sink the application configured.
EventLogger<T> takes an IEventSubscriber (the event aggregator) and an ILogger<T>, and internally constructs an EventPublisher from the subscriber. Its main entry point is LogAndPublish<TEvent>(TEvent @event, bool skipLogging = false) where TEvent : struct, IEvent — the generic-plus-struct constraint is the whole point of the boxing-free dispatch, so don't refactor it to a non-generic IEvent parameter.
Categories
LogCategories is internal static and exposes nested marker types used inside the driver for ILogger<T> resolution (e.g. LogCategories.Command, LogCategories.Connection, LogCategories.SDAM, LogCategories.ServerSelection; plus LogCategories.Client as a non-event category for top-level driver logs). User code cannot reference these marker types — what reaches the user's ILoggerFactory is the decorated string category (MongoDB.Command, MongoDB.Connection, MongoDB.SDAM, MongoDB.ServerSelection, MongoDB.Client), built by LogCategoryHelper.DecorateCategoryName (which also applies MongoDB.Internal / MongoDB.Tests prefixes for callers outside the MongoDB.Bson / MongoDB.Driver / MongoDB.Driver.Core assembly allowlist — see the LogCategoryHelper section below). Filter by those strings in your logging framework. (Note: the per-category template-provider files — Command, Cmap, Connection, Cluster, Sdam — are an internal grouping for log templates and do not 1:1 map to LogCategories nested types.)
Templates
Per-event templates live in StructuredLogTemplateProviders*.cs (one file per category: Command, Cmap, Connection, Cluster, Sdam). Each provider exposes:
GetTemplate(IEvent)— message template with{Param}placeholders.GetParams(IEvent, EventLogFormattingOptions)— substitution values.LogLevel— per event type. Headline: command-monitoring / CMAP / connection-pool & connection-lifecycle / most SDAM templates emit atDebug; the connection message-IO channel andServerDescriptionChangedEventemit atTrace;ClusterEnteredSelectionQueueEventis the loneInformationtemplate; no template currently emits atWarningor higher. Detail by file: in the SDAM template provider the onlyTracetemplate isServerDescriptionChangedEvent(SdamInformationEventisDebug); in the Connection template provider the message-IO templates (ConnectionReceivedMessage,Receiving,ReceivingFailed,SendingMessages,SendingFailed,SentMessagesinStructuredLogTemplateProvidersConnection.cs) are allTrace— that whole sub-channel isTraceby design, while the rest of the Connection templates (lifecycle: opening/opened/failed/closing/closed/created) stay atDebug. Command-monitoring (CommandStarted/Succeeded/Failed) and server-heartbeat templates areDebug. The mechanism supports the fullLogLevelrange; nothing currently usesWarning/Error/Critical.
EventLogFormattingOptions.MaxDocumentSize truncates BSON command/reply documents in logs. Without it, a bulk insert with thousands of documents can flood storage.
LogCategoryHelper
DecorateCategoryName builds the public log-category name by keeping only the last path component of a dot-separated category string and applying a fixed MongoDB / MongoDB.Internal / MongoDB.Tests prefix — e.g. MongoDB.Driver.Core.Logging.LogCategories.Command becomes MongoDB.Command. Nested-type + separators in CLR type names are normalised to . upstream in GetCategoryName<T> (type.FullName.Replace('+', '.')) before DecorateCategoryName is called, so by the time it runs the input is already dot-only — it just splits on ., picks the last component, and re-prefixes.
Common pitfalls
LoggerFactorynot set → no log output (silent). Easy to miss.MaxDocumentSize = 0is not "no limit" —TruncateIfNeededisstr.Length > length ? str.Substring(0, length) + "..." : str, so any non-empty document renders as just"..."(an empty""body is unchanged because0 > 0is false). The default that the user-facingLoggingSettings.MaxDocumentSizeresolves to (viaOptional<int>) isMongoInternalDefaults.Logging.MaxDocumentSize(1000); pass a deliberately largeintif you want effectively unlimited payloads. Warning: theEventLogger<T>constructor (seeCore/Logging/EventLogger.cs) falls back tonew EventLogFormattingOptions(0)when itseventLogFormattingOptionsparameter isnull— this is the aggressive-truncate path. Any internalEventLogger<T>call site that constructs the logger without explicit formatting options (including theEmptylogger) gets this path. End-user code reachesMaxDocumentSizevia theLoggingSettingsconstructor'sOptional<int>default, which correctly resolves to1000; the0fallback is only hit by call sites that bypassLoggingSettings.- SDAM heartbeat spam at Debug/Trace level. The SDAM category contains a mix of levels —
ServerDescriptionChangedEventisTrace, every other heartbeat/server-lifecycle template isDebug, andClusterEnteredSelectionQueueEvent(server-selection wait queue) isInformation. FilteringMongoDB.SDAMtoInformation+silences nearly all SDAM signal except the server-selection waits, which is the right tradeoff for steady-state production; useDebug+when you're actively debugging topology and want the heartbeat detail back. - Synchronous logging on monitor threads. Templates render on the same monitor threads that fire heartbeat / CMAP events. A slow logger backend stalls those threads; the same rule that applies to event subscribers (no
.Result/.Wait()/GetAwaiter().GetResult()— seeCore/Events/AGENTS.md) applies inside any custom logger or sink wired up here. Use async sinks where supported by your logging framework. IsEnabledshort-circuits. Cost when log level is disabled is negligible — don't pre-filter in user code, let the framework do it.
How to test
dotnet test tests/MongoDB.Driver.Tests/MongoDB.Driver.Tests.csproj -f net10.0 \
--filter "FullyQualifiedName~Logging|FullyQualifiedName~LogCategories"Spec runner: tests/MongoDB.Driver.Tests/Specifications/command-logging-and-monitoring/ covers the cross-driver structured-logging suite.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

