feat: 修复雪花id问题
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Autofac;
|
||||
using Autofac.Core.Registration;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,10 +21,11 @@ namespace Yi.Framework.Core.Autofac.Extensions
|
||||
|
||||
public static void RegisterYiModule(this ContainerBuilder builder, AutoFacModuleEnum autoFacModuleEnum, params Assembly[] assemblies)
|
||||
{
|
||||
Logger? _logger = LogManager.Setup().LoadConfigurationFromAssemblyResource(typeof(AutoFacModuleExtensions).Assembly).GetCurrentClassLogger();
|
||||
switch (autoFacModuleEnum)
|
||||
{
|
||||
case AutoFacModuleEnum.PropertiesAutowiredModule:
|
||||
Console.WriteLine($"意框架添加AutoFac模块:{nameof(PropertiesAutowiredModule)}-属性注入模块");
|
||||
_logger.Info($"意框架添加AutoFac模块:{nameof(PropertiesAutowiredModule)}-属性注入模块");
|
||||
new PropertiesAutowiredModule().Load(builder, assemblies);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Buffers.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Data.Json
|
||||
{
|
||||
public class LongToStringConverter : JsonConverter<long>
|
||||
{
|
||||
public override long Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
ReadOnlySpan<byte> span = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;
|
||||
if (Utf8Parser.TryParse(span, out long number, out int bytesConsumed) && span.Length == bytesConsumed)
|
||||
{
|
||||
return number;
|
||||
}
|
||||
|
||||
if (long.TryParse(reader.GetString(), out number))
|
||||
{
|
||||
return number;
|
||||
}
|
||||
}
|
||||
|
||||
return reader.GetInt64();
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, long value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,22 @@
|
||||
using AspNetCore.Microsoft.AspNetCore.Hosting;
|
||||
using AspNetCore.Microsoft.AspNetCore.Hosting;
|
||||
using Yi.Framework.Core.Autofac.Extensions;
|
||||
using Yi.Framework.Core.Autofac.Modules;
|
||||
using Yi.Framework.Core.Extensions;
|
||||
using Yi.BBS.Web;
|
||||
using Yi.Framework.Core.Module;
|
||||
using NLog.Extensions.Logging;
|
||||
using NLog;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddLogging(builder => { builder.ClearProviders().AddNLog("nlog.config").SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); });
|
||||
Logger? _logger = LogManager.Setup().LoadConfigurationFromAssemblyResource(typeof(Program).Assembly).GetCurrentClassLogger();
|
||||
_logger.Info("-----( ¯ □ ¯ )YiFrameowrk框架启动-----");
|
||||
|
||||
builder.WebHost.UseStartUrlsServer(builder.Configuration);
|
||||
|
||||
builder.UseYiModules(typeof(YiBBSWebModule));
|
||||
|
||||
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>autofacģ<EFBFBD><EFBFBD>,<2C><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
||||
//添加autofac模块,需要添加模块
|
||||
builder.Host.ConfigureAutoFacContainer(container =>
|
||||
{
|
||||
container.RegisterYiModule(AutoFacModuleEnum.PropertiesAutowiredModule, ModuleAssembly.Assemblies);
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
<ProjectReference Include="..\Yi.BBS.Sqlsugar\Yi.BBS.Sqlsugar.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="key.pem">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
||||
@@ -12,6 +12,7 @@ using Yi.Framework.AspNetCore;
|
||||
using Yi.Framework.Data.Json;
|
||||
using Yi.Framework.OperLogManager;
|
||||
using Yi.Framework.Core.Module;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Yi.BBS.Web
|
||||
{
|
||||
@@ -28,7 +29,8 @@ namespace Yi.BBS.Web
|
||||
//添加控制器与动态api
|
||||
services.AddControllers().AddJsonOptions(opt => {
|
||||
opt.JsonSerializerOptions.Converters.Add(new DateTimeJsonConverter("yyyy-MM-dd HH:mm:ss"));
|
||||
});
|
||||
opt.JsonSerializerOptions.Converters.Add(new LongToStringConverter());
|
||||
});
|
||||
|
||||
services.AddAutoApiService(opt =>
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Microsoft.AspNetCore": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
|
||||
51
Yi.Framework.Net6/src/project/BBS/Yi.BBS.Web/nlog.config
Normal file
51
Yi.Framework.Net6/src/project/BBS/Yi.BBS.Web/nlog.config
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true"
|
||||
throwExceptions="false"
|
||||
internalLogLevel="Off">
|
||||
|
||||
<variable name="archiveAboveSize" value="10485760"/>
|
||||
<variable name="maxArchiveFiles" value="50"/>
|
||||
<variable name="layout" value="${date:format=HH\:mm\:ss.fff}|${level}|${threadId:format=threadId}|${logger}${newline}>>${message} ${exception:format=tostring}"/>
|
||||
<variable name="logsRootPath" value="${basedir}/logs/${shortdate}" />
|
||||
|
||||
<targets>
|
||||
<target xsi:type="File"
|
||||
name="AllFile"
|
||||
fileName="${logsRootPath}/AllFile/log.log"
|
||||
layout="${layout}${newline}"
|
||||
archiveAboveSize="${archiveAboveSize}"
|
||||
maxArchiveFiles="${maxArchiveFiles}" />
|
||||
|
||||
<target xsi:type="ColoredConsole"
|
||||
name="ColoredConsole"
|
||||
layout="${layout}${newline}">
|
||||
<highlight-row condition="level == LogLevel.Info" foregroundColor="White" />
|
||||
<highlight-row condition="level == LogLevel.Debug" foregroundColor="Green" />
|
||||
<highlight-row condition="level == LogLevel.Warn" foregroundColor="Yellow" />
|
||||
<highlight-row condition="level == LogLevel.Error" foregroundColor="Red" />
|
||||
<highlight-row condition="level == LogLevel.Fatal" foregroundColor="Red" backgroundColor="White" />
|
||||
</target>
|
||||
|
||||
<target xsi:type="File" name="OwnFile"
|
||||
fileName="${logsRootPath}/OwnFile/log.log"
|
||||
layout="${layout}|Url: ${aspnet-request-url}|Action: ${aspnet-mvc-action}${newline}"
|
||||
archiveAboveSize="${archiveAboveSize}"
|
||||
maxArchiveFiles="${maxArchiveFiles}" />
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="Quartz.*" maxlevel="Warn" final="true" />
|
||||
<logger name="Grpc.*" maxlevel="Debug" final="true" />
|
||||
<logger name="Grpc.*" maxlevel="Trace" final="true" />
|
||||
<logger name="Microsoft.EntityFrameworkCore.*" maxlevel="Warn" final="true" />
|
||||
<logger name="Microsoft.AspNetCore.*" maxlevel="Warn" final="true" />
|
||||
<logger name="Microsoft.AspNetCore.SignalR.*" maxlevel="Warn" final="true" />
|
||||
<logger name="*" minlevel="Information" maxlevel="Fatal" writeTo="AllFile,ColoredConsole"/>
|
||||
<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="ColoredConsole,OwnFile" final="true" />
|
||||
<logger name="Microsoft.*" maxlevel="Info" final="true" />
|
||||
<logger name="*" minlevel="Trace" writeTo="OwnFile" />
|
||||
|
||||
</rules>
|
||||
</nlog>
|
||||
Binary file not shown.
@@ -1,16 +1,22 @@
|
||||
using AspNetCore.Microsoft.AspNetCore.Hosting;
|
||||
using AspNetCore.Microsoft.AspNetCore.Hosting;
|
||||
using Yi.Framework.Core.Autofac.Extensions;
|
||||
using Yi.Framework.Core.Autofac.Modules;
|
||||
using Yi.Framework.Core.Extensions;
|
||||
using Yi.BBS.Web;
|
||||
using Yi.Framework.Core.Module;
|
||||
using NLog.Extensions.Logging;
|
||||
using NLog;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddLogging(builder => { builder.ClearProviders().AddNLog("nlog.config").SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); });
|
||||
Logger? _logger = LogManager.Setup().LoadConfigurationFromAssemblyResource(typeof(Program).Assembly).GetCurrentClassLogger();
|
||||
_logger.Info("-----( ¯ □ ¯ )YiFrameowrk框架启动-----");
|
||||
|
||||
builder.WebHost.UseStartUrlsServer(builder.Configuration);
|
||||
|
||||
builder.UseYiModules(typeof(YiBBSWebModule));
|
||||
|
||||
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>autofacģ<EFBFBD><EFBFBD>,<2C><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
||||
//添加autofac模块,需要添加模块
|
||||
builder.Host.ConfigureAutoFacContainer(container =>
|
||||
{
|
||||
container.RegisterYiModule(AutoFacModuleEnum.PropertiesAutowiredModule, ModuleAssembly.Assemblies);
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
<ProjectReference Include="..\Yi.BBS.Sqlsugar\Yi.BBS.Sqlsugar.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="key.pem">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
||||
@@ -12,6 +12,7 @@ using Yi.Framework.AspNetCore;
|
||||
using Yi.Framework.Data.Json;
|
||||
using Yi.Framework.OperLogManager;
|
||||
using Yi.Framework.Core.Module;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Yi.BBS.Web
|
||||
{
|
||||
@@ -28,7 +29,8 @@ namespace Yi.BBS.Web
|
||||
//添加控制器与动态api
|
||||
services.AddControllers().AddJsonOptions(opt => {
|
||||
opt.JsonSerializerOptions.Converters.Add(new DateTimeJsonConverter("yyyy-MM-dd HH:mm:ss"));
|
||||
});
|
||||
opt.JsonSerializerOptions.Converters.Add(new LongToStringConverter());
|
||||
});
|
||||
|
||||
services.AddAutoApiService(opt =>
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Microsoft.AspNetCore": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user