.net core 進入每個頁面都新增日誌
阿新 • • 發佈:2021-01-19
新增中介軟體判斷讀取資源是否是頁面,如果是頁面則新增日誌:
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.Use(c => { return new RequestDelegate( async context => { // await context.Response.WriteAsync("Hello world start"); //使用Contains則RequestDelegate會報錯所以改用IndexOf if (context.Request.Path.Value.IndexOf(".html") >= 0) { string ticket = context.Request.Query["ticket"].ToString(); Guid userGuid; string s0; DateTime dt;
//如果ticket有效,能夠正常找到使用者名稱,則新增日誌, if (TicketRingContext.Parse(ticket, out userGuid, out s0, out dt)) { LogInfo LOG = new LogInfo(); LOG.Title = "進入頁面"; LOG.Content = context.Request.Path.Value; LOG.OperationAction = "140000"; LOG.MenuId = "301"; LOG.ticket = ticket; LOG.SessionId = ""; LOG.System = EnumSysNo.個人工作臺.ToString(); LOG.Remark = ""; LogRedis.WriteLogRedis(LOG); } } await c.Invoke(context); } ); }); }