NAccLogger – .Net Accurate Logger for C#

NAccLoggerThis C # class library provides functionality for saving text and data to different targets, and allows you to select only relevant log element categories, log types, and source objects through the appropriate filters.

It is possible to choose the properties of the log elements from ten basic elements (including the caller information: objet, type, name of the method / property, name of the source file and line number)and to control the formatting of the texts of Log messages.


This C # library is open source (licence MIT).Find it on GitHub : Wiki project and sources
Install the library in Visual Studio from NuGet : > Package-Install NAccLogger

Several standard loggers are provided, but new ones can be developed in a very simple way. Each component of the library can also be expanded to support new features. Designed to be lightweight and fast. Filters and formatting can be controlled globally or individually for each logger. The library can store logs in real time and / or postpone storage by log item blocks. The library supports multithreaded contexts.

Examples of use:

First, reference the library :

using NAccLogger;
using NAccLogger.Ext;


call of a log function:

this.Warning(LogCategory.Application)?.T(“this is a warning message”);
this the current object using an extension method retrieves the object ( this ) that calls the library. Allows you to store caller type information in addition to the path of the source file, line number, method name, or property making the call
Warning has an object extension method of NAccLogger via NAccLogger.Ext using the operation records a log item of type Warning . Other possible operations: Error, Info, Debug, Fatal, header
LogCategory.App as parameter the category of the log item, among the possible values ​​of LogCategory or a custom value. This parameter can be omitted
?. the conditional Null operator? represents the filtering of the log operation invocation. It bypasses the evaluation of the expression on the right to avoid string constructions and additional code if the invocation is not required by the logger filters the object obtained via?. is an invoker of loggers selected by filtering. This object is cached (1 per thread) by NAccLogger to build filtering once. It can be stored and reused.
T this method corresponds to the deferred conditional method, executed when the result of the filtering is not null. If necessary, it performs the initial method call (for exemple Warning,Debug)

result: Logger SystemConsole (with coloring enabled)


the call of a log function (Info, Debug, Warning, Error, Fatal) leads to:
1. the construction of a log item via a factory factory
2. the textual formatting of the item by a formatter

The default properties of an item are described by the properties of the NAccLogger.Impl.LogItem

property description example
Index identifier of the log item: auto-incremented unique number 31
DateTime date and time of the call of the log function, formatting according to the local culture of the logger 28/09/2018 00:14:29
HostName hostname of the machine from where the call was made
IPAddress IP address of the caller. the factory of the item presents by default the IP of the network interface on which internet is available
ProcessId caller process ID 5988
ProcessName name of the process (executable) of the caller NAccLogger.Test
ThreadId identifier of the thread in the caller process 1
LogType text of the log item type name (Info,Debug,Warning,Error,Fatal). filtering property Warning
LogCategory category name of the log Application
Text text of the log message (formatting of item properties)
CallerTypeName full name of the caller type (if call via extension method, empty if call via static facade) NAccLogger.Test.TestClass1
CallerMemberName name of the method or property that originated the call to the log function TestMethod1
CallerFilePath complete path of the source file where the call code of the log function is located P:\NAccLogger\NAccLogger.Test\TestClassBase.cs
CallerLineNumber number of the line of the call in the source file 130


The loggers are the components in charge of the restitution of the log items on the associated target. The basic loggers are:

log to the system console
colorization can be set or disabled
windows event log
log to a windows event log
custom or standard
log in the output of Visual Studio
The colorization is obtained with the module VSColorOutput of Mike Ward & Ann Arbor
log to file

  • log size limit (here 10KB)
  • log historization (on reached size or date exceeded)
  • log indexing with the same logging date


log to network over TCP


not completed


not completed

Leave a Reply