zhaolei
9 days ago 4a2e5b9a21940f11757be37d99f0944e240e908b
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
#if !NET45
using Prow.Logging;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Specialized;
 
namespace Microsoft.Extensions.DependencyInjection
{
    /// <summary>
    /// 数据库日志配置服务注入方法扩展类
    /// </summary>
    public static class DBLoggerFactoryExtensions
    {
        /// <summary>
        /// 添加文件日志功能到服务容器中
        /// </summary>
        /// <param name="builder">The <see cref="ILoggingBuilder"/> to use.</param>
        /// <param name="action">日志操作类回调方法,使用者在此回调中将异常记录到数据库中</param>
        public static ILoggingBuilder AddDBLogger(this ILoggingBuilder builder, Action<Exception, NameValueCollection> action)
        {
            if (action == null) throw new ArgumentNullException(nameof(action));
            builder.Services.AddSingleton<ILoggerProvider>(new DBLoggerProvider(builder.Services, action));
            return builder;
        }
    }
}
#endif