1. Kamyar Inanloo
  2. FluentNLog

Wiki

Clone wiki

FluentNLog / Home

What is inside?

There are many ways to make a Fluent interface. One of them is to write extension methods for currently working classes, which suits for cases like NLog since they have already configuration classes. If you remind Fluent NHibernate configuration structure, you would understand the way FluentNLog works.

Getting Started

Note that this package just tries to make Fluent API over NLog configuration, not using logger classes. The sample is included in the source. Very easily you can get the configuration head and continue with method chain:

var config = new LoggingConfiguration();

The method chain is, as expected from a good fluent interface, self describing. That is, each part of chain will help you add the next part using your IDE autocompletion feature.

onfig.Fluently(
NLogRule
 .Log("*")
 .Level(LogLevel.Error)
 .ToFile("${basedir}/${shortdate}.log")
 .Name("global")
 .ArchiveEvery(FileArchivePeriod.Day)
,NLogRule
.Log("Dummy")
.ToEmail("someone@example.com")
);

Now you can set the default configuration to the variable:

LogManager.Configuration = config;

The next main TODO of the project is to make the library capable of automatically read the XML configuration and merge it with the fluent one, as in Fluent NHibernate.Do not forget that the library is not complete and mature yet. We need to add more logger sinks. But please provide me with your issue reports including bugs and feature requests.

Happy coding.

Updated