asp.net core 6網站藉由Serilog上線添加只有在發生error跟例外的txt log檔並限制只保留2天以內的
~\Program.cs 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 using BingoSys.Data ; using BingoSys.Hubs ; using BingoSys.Services ; using Microsoft.AspNetCore.Identity ; using Microsoft.AspNetCore.Identity.UI.Services ; using Microsoft.EntityFrameworkCore ; using Serilog ; using Serilog.Events ; using System.Text.Encodings.Web ; using System.Text.Unicode ; var builder = WebApplication.CreateBuilder(args); // 初始化 Serilog,名稱像是 myapp_20231029.txt,定時只保留最近3天的日誌檔案 Log.Logger = new LoggerConfiguration() .MinimumLevel.Override( "Microsoft" , LogEventLevel.Warning) // 過濾 Microsoft 日誌 .MinimumLevel.Override( "Microsoft.EntityFrameworkCore" , LogEventLevel.Error) // 只有在出現錯誤時才記錄 EF Core 的日誌 .WriteTo.File( "logs/myapp_.txt" , rollingInterval: Rolling...