LoggerExtensions.BeginScope(ILogger, String, Object[]) 方法

定义

设置消息格式并创建范围。

public:
[System::Runtime::CompilerServices::Extension]
 static IDisposable ^ BeginScope(Microsoft::Extensions::Logging::ILogger ^ logger, System::String ^ messageFormat, ... cli::array <System::Object ^> ^ args);
public static IDisposable BeginScope (this Microsoft.Extensions.Logging.ILogger logger, string messageFormat, params object[] args);
public static IDisposable BeginScope (this Microsoft.Extensions.Logging.ILogger logger, string messageFormat, params object?[] args);
public static IDisposable? BeginScope (this Microsoft.Extensions.Logging.ILogger logger, string messageFormat, params object?[] args);
static member BeginScope : Microsoft.Extensions.Logging.ILogger * string * obj[] -> IDisposable
<Extension()>
Public Function BeginScope (logger As ILogger, messageFormat As String, ParamArray args As Object()) As IDisposable

参数

logger
ILogger

要在其中创建范围的 ILogger

messageFormat
String

采用消息模板格式的日志消息的格式字符串。 示例: “从 {Address} 登录的用户 {User}”

args
Object[]

一个对象数组,其中包含零个或多个要设置格式的对象。

返回

IDisposable

一个可处置的范围对象。 可以为 null。

示例

using(logger.BeginScope("Processing request from {Address}", address)) { }

适用于