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 ·11 revisions

Fluent Logger API

NLog 5.0 introduces new fluentLogEventBuilder that can be activated with one of these extensions methods forILogger:

  • ForLogEvent - Builds base LogEvent
  • ForTraceEvent - Builds LogEvent with Trace-LogLevel
  • ForDebugEvent - Builds LogEvent with Debug-LogLevel
  • ForInfoEvent - Builds LogEvent with Info-LogLevel
  • ForWarnEvent - Builds LogEvent with Warn-LogLevel
  • ForErrorEvent - Builds LogEvent with Error-LogLevel
  • ForFatalEvent - Builds LogEvent with Fatal-LogLevel
  • ForExceptionEvent - Builds LogEvent with Exception and Error-LogLevel

To complete the fluent builder then callLog() to capture availablecallsite information with help fromCaller Member Attributes, and then writes the actual LogEvent to any configured NLog targets.

Replaces the oldFluent-namespace and also reduces memory-allocation when LogLevel not enabled.

Examples

Writing Info Message

_logger.ForInfoEvent().Message("This is a fluent message {0}.","test").Property("PropertyName","PropertyValue").Log();

Writing Exception Message.

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

-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