All Projects → loresoft → NLog.Mongo

loresoft / NLog.Mongo

Licence: MIT license
MongoDB Target for NLog

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to NLog.Mongo

pytest-mock-resources
Pytest Fixtures that let you actually test against external resource (Postgres, Mongo, Redshift...) dependent code.
Stars: ✭ 84 (+35.48%)
Mutual labels:  mongo
docker-mongodb-backup
Docker MongoDB Backup Container based on Alpine w/S6 init, Zabbix Monitoring
Stars: ✭ 27 (-56.45%)
Mutual labels:  mongo
zoia2 old
Zoia CMS
Stars: ✭ 24 (-61.29%)
Mutual labels:  mongo
create-mern-ts-app
Create a Mongo-Express-React-Node Application written in TypeScript out of the box.
Stars: ✭ 30 (-51.61%)
Mutual labels:  mongo
discord-economy-super
Easy and customizable economy module for your Discord bot.
Stars: ✭ 28 (-54.84%)
Mutual labels:  mongo
NodeScalableArchitecture
A Scalable Node Architecture/Server. This repository contains a complete implementation of writing scalable nodejs server/architecture on my medium blog.
Stars: ✭ 62 (+0%)
Mutual labels:  mongo
express-mongo-jwt-boilerplate
Express Mongo JsonWebToken boilerplate
Stars: ✭ 100 (+61.29%)
Mutual labels:  mongo
py-mongo-sync
Oplog-based data sync tool that synchronizes data from a replica set to another deployment, e.g.: standalone, replica set, and sharded cluster.
Stars: ✭ 102 (+64.52%)
Mutual labels:  mongo
deploy shard mongodb
This repository has a set of scripts and resources required for deploying MongoDB replicated sharded cluster.
Stars: ✭ 17 (-72.58%)
Mutual labels:  mongo
docker-mongo-auth
Easily setup authentication on Docker's Official MongoDB image.
Stars: ✭ 78 (+25.81%)
Mutual labels:  mongo
eReports-open-source
Sistema de envio e agendamento de relatórios
Stars: ✭ 30 (-51.61%)
Mutual labels:  mongo
mongo-dot-notation
Transform objects to MongoDB update instructions
Stars: ✭ 35 (-43.55%)
Mutual labels:  mongo
moongoon
An object-document mapper for MongoDB. 🌙
Stars: ✭ 41 (-33.87%)
Mutual labels:  mongo
product-catalog-spring-mvc-demo
A Product Catalog Demonstration Project Using Spring MVC and Mongo DB
Stars: ✭ 16 (-74.19%)
Mutual labels:  mongo
docker-db-backup
Backup mutltiple databases types on a scheduled basis with many customizable options
Stars: ✭ 302 (+387.1%)
Mutual labels:  mongo
toutiao
模仿今日头条,实现 APP 端,Server 端, Web 管理端
Stars: ✭ 17 (-72.58%)
Mutual labels:  mongo
php-mongo-migrator
Migrations of MongoDB. Part of @PHPMongoKit
Stars: ✭ 29 (-53.23%)
Mutual labels:  mongo
Meteor-logger-mongo
🍃 Meteor Logging: Store application log messages in MongoDB
Stars: ✭ 20 (-67.74%)
Mutual labels:  mongo
NLog.Owin.Logging
NLog logging adapter for OWIN
Stars: ✭ 25 (-59.68%)
Mutual labels:  nlog
mongtype
🚀 MongoDB Repository Pattern for Node written in TypeScript
Stars: ✭ 63 (+1.61%)
Mutual labels:  mongo

NLog.Mongo

Writes NLog messages to MongoDB.

Build status

NuGet Version

Download

The NLog.Mongo library is available on nuget.org via package name NLog.Mongo.

To install NLog.Mongo, run the following command in the Package Manager Console

PM> Install-Package NLog.Mongo

More information about NuGet package avaliable at https://nuget.org/packages/NLog.Mongo

Development Builds

Development builds are available on the myget.org feed. A development build is promoted to the main NuGet feed when it's determined to be stable.

In your Package Manager settings add the following package source for development builds: http://www.myget.org/F/loresoft/

Configuration Syntax

<extensions>
  <add assembly="NLog.Mongo"/>
</extensions>

<targets>
  <target xsi:type="Mongo"
          name="String"
          connectionName="String"
          connectionString="String"
          collectionName="String"
          cappedCollectionSize="Long"
          cappedCollectionMaxItems="Long"
          databaseName="String"
          includeDefaults="Boolean">
    
    <!-- repeated --> 
    <field name="String" layout="Layout" bsonType="Boolean|DateTime|Double|Int32|Int64|String"  />
    
    <!-- repeated --> 
    <property name="String" layout="Layout" bsonType="Boolean|DateTime|Double|Int32|Int64|String"  />
  </target>
</targets>

Parameters

General Options

name - Name of the target.

Connection Options

connectionName - The name of the connection string to get from the config file.

connectionString - Connection string. When provided, it overrides the values specified in connectionName.

databaseName - The name of the database, overrides connection string database.

Collection Options

collectionName - The name of the MongoDB collection to write logs to.

cappedCollectionSize - If the collection doesn't exist, it will be create as a capped collection with this max size.

cappedCollectionMaxItems - If the collection doesn't exist, it will be create as a capped collection with this max number of items. cappedCollectionSize must also be set when using this setting.

Document Options

includeDefaults - Specifies if the default document is created when writing to the collection. Defaults to true.

field - Specifies a root level document field. There can be multiple fields specified.

property - Specifies a dictionary property on the Properties field. There can be multiple properties specified.

includeEventProperties - Specifies if LogEventInfo Properties should be automatically included. Defaults to true.

Examples

Default Configuration with Extra Properties

NLog.config target

<target xsi:type="Mongo"
        name="mongoDefault"
        connectionString="mongodb://localhost/Logging"
        collectionName="DefaultLog"
        cappedCollectionSize="26214400">
  <property name="ThreadID" layout="${threadid}" bsonType="Int32" />
  <property name="ThreadName" layout="${threadname}" />
  <property name="ProcessID" layout="${processid}" bsonType="Int32" />
  <property name="ProcessName" layout="${processname:fullName=true}" />
  <property name="UserName" layout="${windows-identity}" />
</target>

Default Output JSON

{
    "_id" : ObjectId("5184219b545eb455aca34390"),
    "Date" : ISODate("2013-05-03T20:44:11Z"),
    "Level" : "Error",
    "Logger" : "NLog.Mongo.ConsoleTest.Program",
    "Message" : "Error reading file 'blah.txt'.",
    "Exception" : {
        "Message" : "Could not find file 'C:\\Projects\\github\\NLog.Mongo\\Source\\NLog.Mongo.ConsoleTest\\bin\\Debug\\blah.txt'.",
        "Text" : "System.IO.FileNotFoundException: Could not find file 'C:\\Projects\\github\\NLog.Mongo\\Source\\NLog.Mongo.ConsoleTest\\bin\\Debug\\blah.txt' ...",
        "Type" : "System.IO.FileNotFoundException",
        "Source" : "mscorlib",
        "MethodName" : "WinIOError",
        "ModuleName" : "mscorlib",
        "ModuleVersion" : "4.0.0.0"
    },
    "Properties" : {
        "ThreadID" : 10,
        "ProcessID" : 21932,
        "ProcessName" : "C:\\Projects\\github\\NLog.Mongo\\Source\\NLog.Mongo.ConsoleTest\\bin\\Debug\\NLog.Mongo.ConsoleTest.exe",
        "UserName" : "pwelter",
        "Test" : "ErrorWrite",
        "CallerMemberName" : "Main",
        "CallerFilePath" : "c:\\Projects\\github\\NLog.Mongo\\Source\\NLog.Mongo.ConsoleTest\\Program.cs",
        "CallerLineNumber" : "43"
    }
}

Custom Document Fields

NLog.config target

<target xsi:type="Mongo"
        name="mongoCustom"
        includeDefaults="false"
        connectionString="mongodb://localhost"
        collectionName="CustomLog"
        databaseName="Logging"
        cappedCollectionSize="26214400">
  <field name="Date" layout="${date}" bsonType="DateTime" />
  <field name="Level" layout="${level}"/>
  <field name="Message" layout="${message}" />
  <field name="Logger" layout="${logger}"/>
  <field name="Exception" layout="${exception:format=tostring}" />
  <field name="ThreadID" layout="${threadid}" bsonType="Int32" />
  <field name="ThreadName" layout="${threadname}" />
  <field name="ProcessID" layout="${processid}" bsonType="Int32" />
  <field name="ProcessName" layout="${processname:fullName=true}" />
  <field name="UserName" layout="${windows-identity}" />
</target>

Custom Document Fields JSON output

{
    "_id" : ObjectId("5187abc2545eb467ecce9184"),
    "Date" : ISODate("2015-02-02T17:31:20.728Z"),
    "Level" : "Debug",
    "Message" : "Sample debug message",
    "Logger" : "NLog.Mongo.ConsoleTest.Program",
    "ThreadID" : 9,
    "ProcessID" : 26604,
    "ProcessName" : "C:\\Projects\\github\\NLog.Mongo\\Source\\NLog.Mongo.ConsoleTest\\bin\\Debug\\v4.5\\NLog.Mongo.ConsoleTest.exe",
    "UserName" : "pwelter"
}

Custom Object Properties

NLog.config target

<target xsi:type="Mongo"
        name="mongoCustomJsonProperties"
        includeEventProperties="false"
        connectionString="mongodb://localhost"
        collectionName="CustomLog"
        databaseName="Logging"
        cappedCollectionSize="26214400">
    <field name="Properties" bsonType="Object">
        <layout type="JsonLayout" includeAllProperties="true" includeMdlc="true" maxRecursionLimit="10">
            <attribute name="ThreadID" layout="${threadid}" encode="false" />
            <attribute name="ProcessID" layout="${processid}" encode="false" />
            <attribute name="ProcessName" layout="${processname:fullName=false}" />
        </layout>
    </field>
</target>

Custom Object Properties JSON output

{
    "_id" : ObjectId("5184219b545eb455aca34390"),
    "Date" : ISODate("2013-05-03T20:44:11Z"),
    "Level" : "Error",
    "Logger" : "NLog.Mongo.ConsoleTest.Program",
    "Message" : "Error reading file 'blah.txt'.",
    "Exception" : {
        "Message" : "Could not find file 'C:\\Projects\\github\\NLog.Mongo\\Source\\NLog.Mongo.ConsoleTest\\bin\\Debug\\blah.txt'.",
        "Text" : "System.IO.FileNotFoundException: Could not find file 'C:\\Projects\\github\\NLog.Mongo\\Source\\NLog.Mongo.ConsoleTest\\bin\\Debug\\blah.txt' ...",
        "Type" : "System.IO.FileNotFoundException",
        "Source" : "mscorlib",
        "MethodName" : "WinIOError",
        "ModuleName" : "mscorlib",
        "ModuleVersion" : "4.0.0.0"
    },
    "Properties" : {
        "ThreadID" : 10,
        "ProcessID" : 21932,
        "ProcessName" : "NLog.Mongo.ConsoleTest.exe",
        "Product": { "Name": "Foo", "Id": 42 }
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].