using NCC.Templates.Extensions; using Microsoft.Extensions.Logging; using System; namespace NCC.Logging { /// /// 构建字符串日志部分类 /// public sealed partial class StringLoggingPart { /// /// 设置消息 /// /// public StringLoggingPart SetMessage(string message) { // 支持读取配置渲染 if (message != null) Message = message.Render(); return this; } /// /// 设置日志级别 /// /// public StringLoggingPart SetLevel(LogLevel level) { Level = level; return this; } /// /// 设置消息格式化参数 /// /// public StringLoggingPart SetArgs(params object[] args) { if (args != null && args.Length > 0) Args = args; return this; } /// /// 设置事件 Id /// /// public StringLoggingPart SetEventId(EventId eventId) { EventId = eventId; return this; } /// /// 设置日志分类 /// /// public StringLoggingPart SetCategory() { CategoryType = typeof(TClass); return this; } /// /// 设置日志分类名 /// /// public StringLoggingPart SetCategory(string categoryName) { if (!string.IsNullOrWhiteSpace(categoryName)) CategoryName = categoryName; return this; } /// /// 设置异常对象 /// public StringLoggingPart SetException(Exception exception) { if (exception != null) Exception = exception; return this; } /// /// 设置日志服务作用域 /// /// /// public StringLoggingPart SetLoggerScoped(IServiceProvider serviceProvider) { if (serviceProvider != null) LoggerScoped = serviceProvider; return this; } } }