logrythmik / nlog.mongodb Goto Github PK
View Code? Open in Web Editor NEWAn NLog Target for MongoDB persistence.
Home Page: http://logrythmik.github.com/NLog.MongoDB/
License: Other
An NLog Target for MongoDB persistence.
Home Page: http://logrythmik.github.com/NLog.MongoDB/
License: Other
The following log line generates an error
__logger.Debug("Can I throw this exception (Debug)", new FileNotFoundException("Could not find file"));
Stack Trace
System.ArgumentException was unhandled by user code
Message=.NET type System.IO.FileNotFoundException cannot be mapped to a BsonValue.
Source=MongoDB.Bson
StackTrace:
at MongoDB.Bson.BsonTypeMapper.MapToBsonValue(Object value) in C:\build\mongo-csharp-driver\Bson\ObjectModel\BsonTypeMapper.cs:line 156
at MongoDB.Bson.BsonValue.Create(Object value) in C:\build\mongo-csharp-driver\Bson\ObjectModel\BsonValue.cs:line 1044
at NLog.MongoDB.BsonDocumentExtensions.AddField(BsonDocument doc, String name, Object value)
at NLog.MongoDB.LogEventInfoExtensions.ToBsonDocument(LogEventInfo logEvent)
at NLog.MongoDB.MongoDBTarget.BuildBsonDocument(LogEventInfo logEvent)
at NLog.MongoDB.MongoDBTarget.Write(LogEventInfo logEvent)
at NLog.Targets.Target.Write(AsyncLogEventInfo logEvent)
InnerException:
Should the "exception' branch of the switch statement in AddFields() method in BsonDocumentExtensions.cs (line 17) be refactored to remove it from the switch statement and instead convert it into its own IF statement
if (unifiedName.EndsWith("exception"))
{
doc[name] = BuildExceptionBsonDocument((Exception)value); return;
}
It was requested on my blog to enable the logger to use connection strings. I am going to add the ability to either configure a connectionString or reference an existing one.
When I used nuget to pull down this package into an asp.net mvc 4 application and tried to log anything, I get this error: An Array value cannot be written to the root level of a BSON document.
The same error occurred when I created a new project too. Could you test it and see what is wrong?
public class HomeController : Controller
{
private Logger logger = LogManager.GetCurrentClassLogger();
public ActionResult Index()
{
logger.Error("test");
return View();
}
}
config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extensions>
<add assembly="NLog.MongoDB"/>
</extensions>
<targets>
<target name="Mongo" type="MongoDB" connectionString="mongodb://localhost/nlog" />
</targets>
<rules>
<logger name="*" minLevel="Info" appendTo="Mongo"/>
</rules>
</nlog>
NLog is MIT. MongoDB C# driver is Apache 2. I wouldn't mind either of those licenses, just don't make it any form of GPL. I need a license so that my company can actually take it seriously as a library they'd consider using.
Could we have the ability of configuring the Nlog mongodb collection as a capped collection, so we can limit the size and/or number of the logs.
The logic in the default case, of falling back on the string representation of an object if no mapping is available, would be preferable to failing to log. I will provide a pull request.
Let's say that just several fields of the large LogEventInfoData object contain useful information. So as a NLog.MongoDB consumer I would like to put into database just these valueable fields. Also I would like to be able to manage list of fields to store in NLog.config file.
<target type="MongoDB" name="Mongo-DynamicFields" connectionName="MongoDB">
<field name="timestamp" layout="${date}" />
<field name="level" layout="${level}" />
<field name="message" layout="${message}" />
<field name="exception" layout="${exception}" />
</target>
The offical document is still using event-context as a sample of custom layout, even it is deprecated.
https://github.com/nlog/nlog/wiki/EventContext-Layout-Renderer
Maybe add following line to LogEventInfoExtensions.ToBsonDocument() can make it compatible to both.
doc.AddField("context", logEvent.Parameters);
For now using NLog.MongoDB with 1.7 of MongoDB C# driver - impossible.
Please update version of used driver to 1.7
I pulled the NuGet package through VS2012 yesterday and it was not the latest version. The CollectionName field is missing, and I wasn't able to get database logging working with ConnectionName.
I downloaded and built the latest source and everything works now. Are the binaries in NuGet out of date?
Since NLog & MongoDB C# drivers are both on NuGet, and since you're using NuGet to reference them, it would make sense if we created a NuGet package for NLog.MongoDB also.
Since the timestamp gets written to the DB as a string and not an ISODate there is no way to reliably sort on that field.
Nuget 0.7.0 contains NLog.MongoDB.dll 0.6.0.
Is that right?
The C# MongoDb driver correctly rejects writing MongoDb documents where field names contain '$' or '.'. As a result NLog.MongoDB fails to write log messages where an Exception's Data member has keys that contain these characters. NLog.MongoDB should replace them with something else.
See http://docs.mongodb.org/manual/core/document/ and http://docs.mongodb.org/manual/faq/developers/#faq-dollar-sign-escaping
Will submit pull request.
Nuget package ver 0.3.0 does not contain binary.
Though the package followed the updates allowing a collectionName (great idea btw), it contains an earlier build of MongoTarget that uses the logger name and throws an exception if you specify a collectionName in the nlog configuration
Please, consider to move all connection details (host, port..) from MongoDBTarget and replace them with a simple connection string name. This will allow to have all application connection data in a single place: connectionStrings section of config file, that means easy maintenance and simple config transformation rules.
Hi guys.
Thank you for this tool. I have to ask you. Can you please update the driver Mongo to the latest version? In our project uses Mongo driver the last version (1.8.3), and your tool doesn't work. I cloned your project with git and updated the driver.After that all parts work is fine. How quickly can you do it? I have a ready solution and I can update repository. How quickly can you update the nuget?.
Thanks in Advance
Could you be so kind to add Nuget package with signed assembly for .NET 3.5.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.