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
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應