添加重写VisualDev接口
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Reflection;
|
||||
using JNPF;
|
||||
using JNPF.Logging;
|
||||
using Spire.Xls;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// SqlSugar配置拓展.
|
||||
/// </summary>
|
||||
public static class LoggingConfigureExtensions
|
||||
{
|
||||
const string DATEFORMAT = "HH:mm:ss.fff";
|
||||
|
||||
public static IServiceCollection LoggingConfigure(this IServiceCollection services)
|
||||
{
|
||||
services.AddConsoleFormatter(option =>
|
||||
{
|
||||
option.MessageFormat = LoggerConsoleFormat;
|
||||
}).AddFileLogging(options =>
|
||||
{
|
||||
options.MessageFormat = LoggerFileFormat;
|
||||
options.FileNameRule = fileName => string.Format(fileName, DateTime.Now); // 每天创建一个文件
|
||||
options.HandleWriteError = (writeError) => // 写入失败时启用备用文件
|
||||
{
|
||||
writeError.UseRollbackFileName(Path.GetFileNameWithoutExtension(writeError.CurrentFileName) + "-oops" + Path.GetExtension(writeError.CurrentFileName));
|
||||
};
|
||||
});
|
||||
return services;
|
||||
}
|
||||
private static string LoggerLevelName(LogLevel level)
|
||||
{
|
||||
return level switch
|
||||
{
|
||||
LogLevel.Trace => "Trace",
|
||||
LogLevel.Debug => "Debug",
|
||||
LogLevel.Information => "Info",
|
||||
LogLevel.Warning => "Warn",
|
||||
LogLevel.Error => "Error",
|
||||
LogLevel.Critical => "Crit",
|
||||
_ => "None"
|
||||
};
|
||||
}
|
||||
private static string LoggerFileFormat(LogMessage msg)
|
||||
{
|
||||
var txt = $"{LoggerLevelName(msg.LogLevel)} {msg.LogDateTime.ToString(DATEFORMAT)} {msg.ThreadId}# {msg.Message}";
|
||||
if (msg.Exception != null)
|
||||
{
|
||||
//var EXCEPTION_SEPARATOR_WITHCOLOR = AppendWithColor(default, EXCEPTION_SEPARATOR, logLevelColors).ToString();
|
||||
txt += $"{Environment.NewLine}{msg.Exception}";
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
private static string LoggerConsoleFormat(LogMessage msg)
|
||||
{
|
||||
var fclr = msg.LogLevel switch
|
||||
{
|
||||
LogLevel.Warning => "\u001b[1m\u001b[33m",
|
||||
LogLevel.Error => "\u001b[1m\u001b[31m",
|
||||
_ => "\u001b[39m\u001b[22m"
|
||||
};
|
||||
var txt = $"{fclr}{LoggerLevelName(msg.LogLevel)}\u001b[49m \u001b[36m{msg.LogDateTime.ToString(DATEFORMAT)}\u001b[49m \u001b[39m\u001b[22m{msg.ThreadId}#\u001b[49m {fclr}{msg.Message}\u001b[49m";
|
||||
if (msg.Exception != null)
|
||||
{
|
||||
//var EXCEPTION_SEPARATOR_WITHCOLOR = AppendWithColor(default, EXCEPTION_SEPARATOR, logLevelColors).ToString();
|
||||
txt += $"{Environment.NewLine}{fclr}{msg.Exception}\u001b[49m";
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,23 +15,17 @@ public static class SqlSugarConfigureExtensions
|
||||
public static IServiceCollection SqlSugarConfigure(this IServiceCollection services)
|
||||
{
|
||||
// 获取选项
|
||||
ConnectionStringsOptions connectionStrings = App.GetConfig<ConnectionStringsOptions>("ConnectionStrings", true);
|
||||
ConnectionStringsOptions conn = App.GetConfig<ConnectionStringsOptions>("ConnectionStrings", true);
|
||||
|
||||
List<ConnectionConfig> connectConfigList = new List<ConnectionConfig>();
|
||||
|
||||
string? connectionStr = connectionStrings.DefaultConnection;
|
||||
var dataBase = connectionStrings.DBName;
|
||||
var DBType = (DbType)Enum.Parse(typeof(DbType), connectionStrings.DBType);
|
||||
var ConfigId = connectionStrings.ConfigId;
|
||||
var DBName = connectionStrings.DBName;
|
||||
|
||||
var DBType = (DbType)Enum.Parse(typeof(DbType), conn.DBType);
|
||||
// 默认数据库
|
||||
connectConfigList.Add(new ConnectionConfig
|
||||
{
|
||||
ConnectionString = string.Format(connectionStr, DBName),
|
||||
ConnectionString = string.Format(conn.DefaultConnection, conn.Host, conn.Port, conn.DBName, conn.UserName, conn.Password),
|
||||
DbType = DBType,
|
||||
IsAutoCloseConnection = true,
|
||||
ConfigId = ConfigId,
|
||||
ConfigId = conn.ConfigId,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
MoreSettings = new ConnMoreSettings()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user