TagProviderAttribute(Type, String) Constructor
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the TagProviderAttribute class with custom tags provider.
public:
TagProviderAttribute(Type ^ providerType, System::String ^ providerMethod);
public TagProviderAttribute (Type providerType, string providerMethod);
new Microsoft.Extensions.Logging.TagProviderAttribute : Type * string -> Microsoft.Extensions.Logging.TagProviderAttribute
Public Sub New (providerType As Type, providerMethod As String)
Parameters
- providerType
- Type
A type containing a method that provides a custom set of tags to log.
- providerMethod
- String
The name of a method on the provider type that generates a custom set of tags to log.
Exceptions
providerMethod
or providerType
is null
.
providerMethod
is either an empty string or contains only whitespace.
Examples
[LoggerMessage(1, LogLevel.Warning, "Custom tags for {Param}.")]
static partial void LogMethod(ILogger logger,
[TagProvider(typeof(CustomProvider), nameof(CustomProvider.GetTagsToLog))] ClassToLog o);
public static class CustomProvider
{
public static void GetTagsToLog(ITagCollector collector, ClassToLog? param)
{
collector.Add("Custom_tag_name", param?.MyProperty);
collector.Add(nameof(ClassToLog.AnotherProperty), param?.AnotherProperty);
// ...
}
}
Remarks
You can create your own method that will generate the exact set of tags to log for a given input object.
The method referenced by this constructor should be non-generic, static
, and public
, and it should have two parameters:
- First parameter of type ITagCollector.
- Second parameter of type
T?
, whereT
is the type of logging method parameter that you want to log.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기