-
Notifications
You must be signed in to change notification settings - Fork 2
/
LoggerProviderAliasUtilities.cs
38 lines (34 loc) · 1.32 KB
/
LoggerProviderAliasUtilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* ===============================================
* 功能描述:AspNetCore.Logging.LoggerProviderAliasUtilities
* 创 建 者:WeiGe
* 创建日期:1/2/2019 11:33:31 PM
* ===============================================*/
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace AspNetCore.FileLog
{
internal class LoggerProviderAliasUtilities
{
private const string AliasAttibuteTypeFullName = "Microsoft.Extensions.Logging.ProviderAliasAttribute";
private const string AliasAttibuteAliasProperty = "Alias";
internal static string GetAlias(Type providerType)
{
foreach (var attribute in providerType.GetTypeInfo().GetCustomAttributes(inherit: false))
{
if (attribute.GetType().FullName == AliasAttibuteTypeFullName)
{
var valueProperty = attribute
.GetType()
.GetProperty(AliasAttibuteAliasProperty, BindingFlags.Public | BindingFlags.Instance);
if (valueProperty != null)
{
return valueProperty.GetValue(attribute) as string;
}
}
}
return null;
}
}
}