Blame view

netcore/src/Infrastructure/NCC/Logging/Internal/StringLoggingPartSetters.cs 2.52 KB
de2bd2f9   “wangming”   项目初始化
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  using NCC.Templates.Extensions;
  using Microsoft.Extensions.Logging;
  using System;
  
  namespace NCC.Logging
  {
      /// <summary>
      /// 构建字符串日志部分类
      /// </summary>
      public sealed partial class StringLoggingPart
      {
          /// <summary>
          /// 设置消息
          /// </summary>
          /// <param name="message"></param>
          public StringLoggingPart SetMessage(string message)
          {
              // 支持读取配置渲染
              if (message != null) Message = message.Render();
              return this;
          }
  
          /// <summary>
          /// 设置日志级别
          /// </summary>
          /// <param name="level"></param>
          public StringLoggingPart SetLevel(LogLevel level)
          {
              Level = level;
              return this;
          }
  
          /// <summary>
          /// 设置消息格式化参数
          /// </summary>
          /// <param name="args"></param>
          public StringLoggingPart SetArgs(params object[] args)
          {
              if (args != null && args.Length > 0) Args = args;
              return this;
          }
  
          /// <summary>
          /// 设置事件 Id
          /// </summary>
          /// <param name="eventId"></param>
          public StringLoggingPart SetEventId(EventId eventId)
          {
              EventId = eventId;
              return this;
          }
  
          /// <summary>
          /// 设置日志分类
          /// </summary>
          /// <typeparam name="TClass"></typeparam>
          public StringLoggingPart SetCategory<TClass>()
          {
              CategoryType = typeof(TClass);
              return this;
          }
  
          /// <summary>
          /// 设置日志分类名
          /// </summary>
          /// <param name="categoryName"></param>
          public StringLoggingPart SetCategory(string categoryName)
          {
              if (!string.IsNullOrWhiteSpace(categoryName)) CategoryName = categoryName;
              return this;
          }
  
          /// <summary>
          /// 设置异常对象
          /// </summary>
          public StringLoggingPart SetException(Exception exception)
          {
              if (exception != null) Exception = exception;
              return this;
          }
  
          /// <summary>
          /// 设置日志服务作用域
          /// </summary>
          /// <param name="serviceProvider"></param>
          /// <returns></returns>
          public StringLoggingPart SetLoggerScoped(IServiceProvider serviceProvider)
          {
              if (serviceProvider != null) LoggerScoped = serviceProvider;
              return this;
          }
      }
  }