X Tutup
The Wayback Machine - https://web.archive.org/web/20201022225812/https://github.com/NLog/NLog.StructuredEvents
Skip to content
This repository has been archived by the owner. It is now read-only.
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md


ℹ️ Structured logging has been merged into NLog 4.5 beta


NLog.StructuredEvents Build status codecov

Parsing and rendering of message templates. Fully backwards-compatible with Serilog's message template format and String.Format().

Getting started

Most of the time, you'll use NLog.StructuredEvents as an integrated part of NLog 4.5+. There's no additional API required for this: just pass a message template to ILogger.Info() and any other method that normally accepts a format string:

logger.Info("User {Username} logged in from {IPAddress}", username, ipAddress)
  // -> An event with `Username` and `IPAddress` properties

To use NLog.StructuredEvents as a stand-alone parser or renderer, first install the NuGet package:

Install-Package NLog.StructuredEvents -Pre

Parsing

The TemplateParser.Parse() method converts a message template string into a Template object:

var template = TemplateParser.Parse("User {Username} logged in from {IPAddress}");

You can inspect the individual tokens in the template's Literals and Holes properties.

Rendering

To render a template, the values assigned to each Hole must be provided positionally:

template.Render(CultureInfo.CurrentCulture, "alice", "192.168.10.20");
  // -> User "alice" logged in from "192.168.10.20"  

License

Dual licensed: MIT/BSD (choose one ;))

About

Parser and renderer for structured log events

Topics

Resources

License

Packages

No packages published
You can’t perform that action at this time.
X Tutup