Skip to content
log4net appender to MongoDB database.
C# PowerShell Batchfile
Find file
New pull request
Latest commit 8bb7199 @emadb emadb version 2.2.0

MongoDB appender for log4net

The title says it all. Check Log4Net site or MongoDB site if you need more info.

This is the official .NET implementation for the log4mongo project

To get started, check out @sammleach blog post: .NET Logging with log4mongo-net


Get it on NuGet, or download sources and run build.cmd to build

Appender configuration sample

<appender name="MongoDBAppender" type="Log4Mongo.MongoDBAppender, Log4Mongo">
    MongoDB database connection in the format:
    See for connectionstring options 
    If no database specified, default to "log4net"
    <connectionString value="mongodb://localhost" />
    Name of connectionString defined in web/app.config connectionStrings group, the format is the same as connectionString value.
    Optional, If not provided will use connectionString value
    <connectionStringName value="mongo-log4net" />
    If set, a TTL (Time To Live) index will be created on the Timestamp field.  
    Records older than this value will be deleted.
    <expireAfterSeconds value="3600" />
    Name of the collection in database
    Optional, Defaults to "logs"
    <collectionName value="logs" />

    Maximum size of newly created collection. Optional, Defaults to creating uncapped collections
    <newCollectionMaxSize value='65536' />
    <newCollectionMaxDocs value='5000' />

        <!-- Note: this needs to be "timestamp" and NOT "Timestamp"  for the TTL index to work -->
        <name value="timestamp" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
        <name value="level" />
        <layout type="log4net.Layout.PatternLayout" value="%level" />
        <name value="thread" />
        <layout type="log4net.Layout.PatternLayout" value="%thread" />
        <name value="logger" />
        <layout type="log4net.Layout.PatternLayout" value="%logger" />
        <name value="message" />
        <layout type="log4net.Layout.PatternLayout" value="%message" />
        <name value="mycustomproperty" />
        <layout type="log4net.Layout.RawPropertyLayout">
            <key value="mycustomproperty" />




Thanks to JetBrains for providing us licenses for its excellent tool ReSharper


Something went wrong with that request. Please try again.