Κοινή χρήση μέσω


TagProviderAttribute(Type, String) Constructor

Definition

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?, where T is the type of logging method parameter that you want to log.

Applies to

See also