Skip to content

simonproctor/log4mongo-net

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Installation

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:
	mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
	See http://www.mongodb.org/display/DOCS/Connections 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" />
	<!-- 
	Name of the collection in database
	Optional, Defaults to "logs"
	-->
	<collectionName value="logs" />
	
	<field>
		<name value="timestamp" />
		<layout type="log4net.Layout.RawTimeStampLayout" />
	</field>
	<field>
		<name value="level" />
		<layout type="log4net.Layout.PatternLayout" value="%level" />
	</field>
	<field>
		<name value="thread" />
		<layout type="log4net.Layout.PatternLayout" value="%thread" />
	</field>
	<field>
		<name value="logger" />
		<layout type="log4net.Layout.PatternLayout" value="%logger" />
	</field>
	<field>
		<name value="message" />
		<layout type="log4net.Layout.PatternLayout" value="%message" />
	</field>
	<field>
		<name value="mycustomproperty" />
		<layout type="log4net.Layout.RawPropertyLayout">
			<key value="mycustomproperty" />
		</layout>
	</field>
</appender>

Note about Default Write Concern Change in driver 1.7+

10gen changed the default value for WriteConcern. This change is implemented in MongoDB C# driver starting from 1.7 and is effective only when used with the new MongoDB.Driver.MongoClient class.

For logging concern, the old default is usually better so for now Log4Mongo will keep creating database connection in the old way (by using MongoDB.Driver.MongoServer.Create). At some point (maybe with a major release) we will switch and start using MongoDB.Driver.MongoClient class, so it's best if you explicitly specify WriteConcern related options in the connection string, as described here: Write Concern Options

License

BSD 3

Credits

Thanks to JetBrains for providing us licenses for it's excellent tool ReSharper

ReSharper

About

log4net appender to MongoDB database.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 89.6%
  • PowerShell 10.3%
  • Shell 0.1%