/// <summary> /// Formats and writes an information log message, beginning an intended section. /// </summary> /// <param name="logger">The <see cref="ILogger"/> to write to.</param> /// <param name="logLevel">Entry will be written on this level.</param> /// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> /// <param name="args">An object array that contains zero or more objects to format.</param> /// <returns>An Indent Level that can be disposed to end the indented section.</returns> public static TerminalIndentLevel LogSection(this ILogger logger, LogLevel logLevel, string message, params object?[] args) { logger.Log(logLevel, message, args); return(TerminalIndentLevel.Increase(logger)); }
/// <summary> /// Formats and writes an information log message, beginning an intended section. /// </summary> /// <typeparam name="T">The type of the object to be written.</typeparam> /// <param name="logger">The <see cref="ILogger"/> to write to.</param> /// <param name="logLevel">Entry will be written on this level.</param> /// <param name="eventId">The event id associated with the log.</param> /// <param name="state">The entry to be written. Can be also an object.</param> /// <param name="exception">The exception related to this entry.</param> /// <param name="formatter">Function to create a <see cref="string"/> message of the <paramref name="state"/> and <paramref name="exception"/>.</param> /// <returns>An Indent Level that can be disposed to end the indented section.</returns> public static TerminalIndentLevel LogSection <T>(this ILogger logger, LogLevel logLevel, EventId eventId, T state, Exception exception, Func <T, Exception, string> formatter) { logger.Log(logLevel, eventId, state, exception, formatter); return(TerminalIndentLevel.Increase(logger)); }
/// <summary> /// Formats and writes an information log message with milestone tagging, beginning an intended section. /// </summary> /// <param name="logger">The <see cref="ILogger"/> to write to.</param> /// <param name="exception">The exception to log.</param> /// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> /// <param name="args">An object array that contains zero or more objects to format.</param> /// <example>using (logger.LogMilestoneSection(exception, "Error while processing request from {Address}", address)) { }</example> public static TerminalIndentLevel LogMilestoneSection(this ILogger logger, Exception exception, string message, params object?[] args) { logger.LogMilestone(exception, message, args); return(TerminalIndentLevel.Increase(logger)); }