Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/NLogPublic
Rolf Kristensen edited this pageDec 28, 2024 ·8 revisions

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

Fluent API

Writing info message via fluent API.

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

Writing error message.

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

Caller Info

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{stringtext=File.ReadAllText(path);}catch(Exceptionex){Log.Error().Message("Error reading file '{0}'.",path).Exception(ex).Property("Test","ErrorWrite").Write();}

-Troubleshooting Guide - See available NLog Targets and Layouts:https://nlog-project.org/config

Configuration

Programmatic Configuration

Advanced

Extending NLog

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp