VOOZH about

URL: https://www.nuget.org/packages/NLog.Mongo/

⇱ NuGet Gallery | NLog.Mongo 5.2.0




👁 Image
NLog.Mongo 5.2.0

dotnet add package NLog.Mongo --version 5.2.0
 
 
NuGet\Install-Package NLog.Mongo -Version 5.2.0
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NLog.Mongo" Version="5.2.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NLog.Mongo" Version="5.2.0" />
 
Directory.Packages.props
<PackageReference Include="NLog.Mongo" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NLog.Mongo --version 5.2.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NLog.Mongo, 5.2.0"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NLog.Mongo@5.2.0
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NLog.Mongo&version=5.2.0
 
Install as a Cake Addin
#tool nuget:?package=NLog.Mongo&version=5.2.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

NLog.Mongo

Writes NLog messages to MongoDB.

👁 Build status

👁 NuGet Version

👁 Coverage Status

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

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">
 
 
 <field name="String" layout="Layout" bsonType="Boolean|DateTime|Double|Int32|Int64|String" />
 
 
 <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 }
 }
}
Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 netstandard2.1 is compatible. 
.NET Framework net472 net472 is compatible.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (11)

Showing the top 5 NuGet packages that depend on NLog.Mongo:

Package Downloads
Snow.Gqz.WebApi.Shared

1、升级至.NET6 2、.NET6代码格式整理

Snow.Gqz.Shared.WebApi

1、修复CPU占用率过高问题,_waitMillisecond 由3 调整为 1000。 2、caching模块代码优化调整

HuiBin.Shared.Webapi

Webapi基础类库

HuiBin.Shared.GrpcService

Grpc基础类库

HuiBin.Shared.IdentityServer

IdentityServer基础类库

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on NLog.Mongo:

Repository Stars
danvic712/Grapefruit.VuCore
A front-background project using ASP.NET Core WebApi and Vue.js
Version Downloads Last Updated
5.2.0 451 5/28/2026
5.1.0 6,698 1/20/2026
5.0.0 64,890 12/12/2024
4.7.2 42,883 5/28/2024
4.7.1 23,637 4/7/2024
4.7.0 79,286 7/29/2023
4.6.0.217 96,348 8/20/2022
4.6.0.191 185,916 1/19/2022
4.6.0.161 66,569 6/5/2021
4.6.0.146 19,849 3/31/2021
4.6.0.135 18,805 2/15/2021
4.6.0.123 118,090 10/26/2020
4.6.0.122 2,025 10/26/2020
4.6.0.118 37,144 10/5/2020
4.6.0.117 1,916 10/2/2020
4.6.0.102 163,599 7/2/2020
4.6.0.86 50,631 3/16/2020
4.6.0.68 118,183 12/18/2018
4.5.0.57 80,127 5/7/2018
4.4.0.55 28,479 3/22/2018
Loading failed