添加serilog日志支持和部分其他efcore代码

This commit is contained in:
2021-02-23 16:16:03 +08:00
parent 0f98c15cd4
commit d639db3574
19 changed files with 506 additions and 28 deletions

View File

@@ -1,14 +1,21 @@
using Infrastructure;
using MediatR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Pomelo.EntityFrameworkCore.MySql;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
using QRCodeService.Application.Behaviors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace QRCodeService
@@ -31,6 +38,25 @@ namespace QRCodeService
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "QRCodeService", Version = "v1" });
});
//MediatR
services.AddMediatR(Assembly.GetExecutingAssembly());
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidatorBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(TransactionBehaviour<,>));
//EFCore
services.AddDbContextPool<AppDbContext>(
dbContextOptions => dbContextOptions
.UseMySql(
"server=localhost;user=root;password=root;database=qrcode",
// For common usages, see pull request #1233.
new MariaDbServerVersion(new Version(10, 5, 9)), // use MariaDbServerVersion for MariaDB
mySqlOptions => mySqlOptions
.CharSetBehavior(CharSetBehavior.NeverAppend))
// Everything from this point on is optional but helps with debugging.
.EnableSensitiveDataLogging()
.EnableDetailedErrors()
);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.