Tagolog is a free .NET library for structured logging like a breeze. Tagolog libraries are
- Tagolog
- general tags and tag context support.
- Tagolog.NLog
- adapter for .NET logging library NLog
- Install Tagolog and Tagolog.NLog NuGet packages.
- Surround your code fragments with tag scopes, fill scopes with structured tags (meta information).
using ( var tagScope = TagScopeManager.CreateScope() )
{
scope.Tags[ "UserId" ] = "jdoe";
scope.Tags[ "VirtualMachine" ] = "appserver4.jdoe.tld";
// ...
log.Info( "Stopping virtual machine..." );
// ...
}- Modify your application config file append "tagolog" section. app.config example
- Modify your NLog configuration. NLog.config example
- Use tagologmdcitem or tagologmdc layout renderers to access your tag values
<target fileName="${basedir}/${tagologmdcitem:item=Application}.log.txt"
name="HumanReadableFile" xsi:type="File"
layout="${date:format=HH\:mm\:ss} ${level} ${message}${newline}${tagologmdc:tagKey=#tagKey#:tagValue=#tagValue#:orderBy=true:builtInTags=false:format= [#tagKey#\:#tagValue#]\\n}" />- Use TagologJsonLayout to get your logs with tags in json.
<target name="JsonFile" xsi:type="File" fileName="${basedir}/log.json.txt" >
<layout xsi:type="TagologJsonLayout" SuppressSpaces="True" BuiltInTagsEnabled="True">
<attribute name="TimestampLocal" layout="${longdate}" />
....- Grab json logs with your business tags to your favourite centralized log storage like Elasticsearch or Graylog
Tagolog is open source software, licensed under the terms of BSD license. Tagolog.NLog is open source software, licensed under the terms of BSD license. See license.txt for details.
Use Visual Studio 2013/2015. Solution files are:
- Tagolog.Logging.sln - Tagolog and Tagolog.NLog projects.
- Tagolog.Logging.Examples.sln - Examples.