Logging extensions
These extensions can be grouped in two ways:
- By level and name: Debug, Info, Warn, Error, Fatal.
- By parameters:
- string + T:
- log.Info("Hello, {Who}!", new { Who = "world" });
- string + object[]:
- Produces an event with given message template and given property values (names are inferred from message template).
- log.Info("Hello, {Who}!", "world");
- Exception:
- Produces an event with given exception and no message or properties.
- log.Error(new Exception());
- Exception + string:
- log.Error(new Exception(), "I have failed.");
- Exception + string + T:
- log.Error(new Exception(), "{Who} have/has failed.", new { Who = "I" });
- Exception + string + object[]:
- Produces an event with given exception, message template and given property values (names are inferred from message template).
- log.Error(new Exception(), "{Who} have/has failed.", "He");
- interpolated string:
- Produces an event with given message template and given property values (names are extracted from argument names).
- var Who = "world";log.Info($"Hello, {Who}!");
- Exception + interpolated string:
- Produces an event with given exception, message template and given property values (names are extracted from argument names).
- var Who = "world";log.Info(new Exception(), $"Hello, {Who}!");
See the section about providing property values to extensions to get a grasp of how to provide values for placeholders in message template.
All extensions produce events with timestamp set to current time and level corresponding to method name.
Last modified 1yr ago