修复日志

This commit is contained in:
zpc 2024-08-04 23:21:56 +08:00
parent 76e13adeaf
commit 0dfee5bf90
5 changed files with 19 additions and 6 deletions

View File

@ -265,15 +265,15 @@ namespace HuanMeng.MiaoYu.Code.Base
#endregion
#region
private Logger<MiaoYuBase>? _logger;
public Logger<MiaoYuBase> _Logger
private ILogger<MiaoYuBase>? _logger;
public ILogger<MiaoYuBase> _Logger
{
get
{
if (_logger == null)
{
_logger = _serviceProvider.GetRequiredService<Logger<MiaoYuBase>>();
_logger = _serviceProvider.GetRequiredService<ILogger<MiaoYuBase>>();
}
return _logger;
}
@ -316,7 +316,7 @@ namespace HuanMeng.MiaoYu.Code.Base
}
#region
private Logger<T>? _logger;
public Logger<T> _Logger
public Logger<T> Logger
{
get

View File

@ -9,6 +9,7 @@ using HuanMeng.MiaoYu.Model.Dto.Chat;
using HuanMeng.MiaoYu.Model.EnumModel.User;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@ -66,6 +67,7 @@ namespace HuanMeng.MiaoYu.Code.Character
/// <returns></returns>
public async Task<BaseResponse<CharacterInfoDto>> GetCharacterInfo(RequestCharacterInfo requestCharacterInfo)
{
_Logger.LogInformation("测试");
var charactersinfo = MiaoYuCache.CharacterList.FirstOrDefault(it => it.Id == requestCharacterInfo.CharacterId);
if (charactersinfo == null)
{

View File

@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections;
@ -31,6 +32,7 @@ namespace HuanMeng.MiaoYu.Code.Chat
{
public ChatBLL(IServiceProvider serviceProvider) : base(serviceProvider)
{
//logger.i
}
/// <summary>
@ -41,7 +43,8 @@ namespace HuanMeng.MiaoYu.Code.Chat
/// <exception cref="ArgumentException"></exception>
public async Task<BaseResponse<List<ChatMessageDto>>> GetChatMessage(int characterId)
{
var charact = MiaoYuCache.CharacterList.FirstOrDefault(it => it.Id == characterId);
if (charact == null)
{

View File

@ -18,6 +18,7 @@ using System.Text.Json.Serialization;
using HuanMeng.DotNetCore.Json;
using Newtonsoft.Json.Serialization;
using HuanMeng.MiaoYu.Code.SysDictionary;
using HuanMeng.MiaoYu.Code.Base;
var builder = WebApplication.CreateBuilder(args);
//Log.Logger = new LoggerConfiguration()
// .WriteTo.Console()
@ -27,6 +28,11 @@ builder.Host.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext());
builder.Services.AddSingleton(typeof(ILogger<MiaoYuBase>), serviceProvider =>
{
var loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
return loggerFactory.CreateLogger<MiaoYuBase>();
});
// 检索程序集信息
AssemblyInfo assemblyInfo = AssemblyInfoHelper.GetAssemblyInfo();
// Add services to the container.

View File

@ -23,7 +23,9 @@
"Name": "File",
"Args": {
"path": "../output/logs/log-.txt",
"rollingInterval": "Day"
"rollingInterval": "Day",
"shared": true ,
//"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"
}
}
],