添加重写VisualDev接口

This commit is contained in:
2023-03-23 11:09:53 +08:00
parent 33a5bf0766
commit 05985a0e43
12 changed files with 3026 additions and 2789 deletions

View File

@@ -25,6 +25,7 @@ using System;
using System.Text;
using Top.Api;
using JNPF.Common.Security;
using JNPF.VisualDev;
namespace JNPF.API.Entry;
@@ -32,11 +33,6 @@ public class Startup : AppStartup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddConsoleFormatter(option =>
{
option.MessageFormat = LoggerConsoleFormat;
});
// SqlSugar
services.SqlSugarConfigure();
@@ -140,6 +136,7 @@ public class Startup : AppStartup
services.AddSession();
services.AddMemoryCache(); // 使用本地缓存必须添加
services.LoggingConfigure();
// 日志监听
// services.AddMonitorLogging(options =>
//{
@@ -147,16 +144,6 @@ public class Startup : AppStartup
// options.IgnorePropertyTypes = new[] { typeof(byte[]) };
//});
services.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));
};
});
services.AddUnitOfWork<SqlSugarUnitOfWork>();
services.OSSServiceConfigure();
@@ -164,6 +151,8 @@ public class Startup : AppStartup
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSchedule();
services.AddOverideVisualDev();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, IOptions<SenparcSetting> senparcSetting, IOptions<SenparcWeixinSetting> senparcWeixinSetting)
@@ -201,7 +190,8 @@ public class Startup : AppStartup
app.UseInject(string.Empty);
app.MapWebSocketManager("/api/message/websocket", serviceProvider.GetService<IMHandler>());
//app.MapWebSocketManager("/api/message/websocket", serviceProvider.GetService<IMHandler>());
app.MapWebSocketManager("/websocket", serviceProvider.GetService<IMHandler>());
app.UseEndpoints(endpoints =>
{
@@ -212,45 +202,4 @@ public class Startup : AppStartup
serviceProvider.GetRequiredService<ITimeTaskService>().StartTimerJob();
}
const string DATEFORMAT = "HH:mm:ss.fff";
private 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 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 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;
}
}