A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/nlog/nlog/wiki/FLuent-API below:

Fluent API · NLog/NLog Wiki · GitHub

⚠️ Marked obsolete with NLog 5.0, that introduces Fluent-Logger-API with optimizations to reduce memory allocations.

Writing info message via fluent API.

using NLog.Fluent;

_logger.Info()
       .Message("This is a test fluent message '{0}'.", DateTime.Now.Ticks)
       .Property("Test", "InfoWrite")
       .Write();

Writing error message.

try
{
    string text = File.ReadAllText(path);
}
catch (Exception ex)
{
    _logger.Error()
           .Message("Error reading file '{0}'.", path)
           .Exception(ex)
           .Property("Test", "ErrorWrite")
           .Write();
}

Use the static Log class so you don't have to include loggers in all of classes. The static Log class using .net 4.5 caller info to get the logger from the file name.

Writing info message via static Log class with fluent API.

Log.Info()
   .Message("This is a test fluent message.")
   .Property("Test", "InfoWrite")
   .Write();

Writing error message.

try
{
    string text = File.ReadAllText(path);
}
catch (Exception ex)
{
    Log.Error()
        .Message("Error reading file '{0}'.", path)
        .Exception(ex)
        .Property("Test", "ErrorWrite")
        .Write();
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4