You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
"use strict";(self.webpackChunkfurion=self.webpackChunkfurion||[]).push([[3723],{4391:(e,n,r)=>{r.r(n),r.d(n,{assets:()=>l,contentTitle:()=>s,default:()=>u,frontMatter:()=>o,metadata:()=>c,toc:()=>d});var t=r(5893),i=r(1151);const o={id:"audit",title:"5.4 \u8bf7\u6c42\u5ba1\u8ba1\u65e5\u5fd7",sidebar_label:"5.4 \u8bf7\u6c42\u5ba1\u8ba1\u65e5\u5fd7 (Audit)",description:"\u4efb\u4f55\u82cd\u8747\u90fd\u4e0d\u80fd\u653e\u8fc7"},s=void 0,c={id:"audit",title:"5.4 \u8bf7\u6c42\u5ba1\u8ba1\u65e5\u5fd7",description:"\u4efb\u4f55\u82cd\u8747\u90fd\u4e0d\u80fd\u653e\u8fc7",source:"@site/docs/audit.mdx",sourceDirName:".",slug:"/audit",permalink:"/docs/audit",draft:!1,unlisted:!1,editUrl:"https://gitee.com/dotnetchina/Furion/tree/v4/handbook/docs/audit.mdx",tags:[],version:"current",lastUpdatedBy:"MonkSoul",lastUpdatedAt:1682389320,formattedLastUpdatedAt:"Apr 25, 2023",frontMatter:{id:"audit",title:"5.4 \u8bf7\u6c42\u5ba1\u8ba1\u65e5\u5fd7",sidebar_label:"5.4 \u8bf7\u6c42\u5ba1\u8ba1\u65e5\u5fd7 (Audit)",description:"\u4efb\u4f55\u82cd\u8747\u90fd\u4e0d\u80fd\u653e\u8fc7"},sidebar:"docs",previous:{title:"5.3 \u7b5b\u9009\u5668/\u62e6\u622a\u5668/\u8fc7\u6ee4\u5668/AOP",permalink:"/docs/filter"},next:{title:"5.5 \u4e2d\u95f4\u4ef6 (Middleware)",permalink:"/docs/middleware"}},l={},d=[{value:"5.4.1 \u5ba1\u8ba1\u65e5\u5fd7",id:"541-\u5ba1\u8ba1\u65e5\u5fd7",level:2},{value:"5.4.2 \u8bf7\u6c42\u5ba1\u8ba1\u65e5\u5fd7",id:"542-\u8bf7\u6c42\u5ba1\u8ba1\u65e5\u5fd7",level:2},{value:"5.4.3 <code>LoggingMonitor</code> \u5ba1\u8ba1\u65e5\u5fd7",id:"543-loggingmonitor-\u5ba1\u8ba1\u65e5\u5fd7",level:2},{value:"5.4.4 \u53cd\u9988\u4e0e\u5efa\u8bae",id:"544-\u53cd\u9988\u4e0e\u5efa\u8bae",level:2}];function a(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",...(0,i.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.admonition,{title:"\u5c0f\u77e5\u8bc6",type:"tip",children:(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"Furion"})," \u63d0\u4f9b\u4e86\u975e\u5e38\u5f3a\u5927\u7684 ",(0,t.jsx)(n.code,{children:"LoggingMonitor"})," \u5ba1\u8ba1\u65e5\u5fd7\u529f\u80fd\uff0c\u53ef\u76f4\u63a5\u4f7f\u7528\uff1a",(0,t.jsx)(n.a,{href:"/docs/logging#1811-loggingmonitor-%E7%9B%91%E5%90%AC%E6%97%A5%E5%BF%97",children:"LoggingMonitor \u6587\u6863"})]})}),"\n",(0,t.jsx)(n.h2,{id:"541-\u5ba1\u8ba1\u65e5\u5fd7",children:"5.4.1 \u5ba1\u8ba1\u65e5\u5fd7"}),"\n",(0,t.jsx)(n.p,{children:"\u5728\u4e00\u4e2a\u4f01\u4e1a\u5e94\u7528\u7cfb\u7edf\u4e2d\uff0c\u7528\u6237\u5bf9\u7cfb\u7edf\u6240\u6709\u7684\u64cd\u4f5c\u5305\u62ec\u8bf7\u6c42\u3001\u6570\u636e\u5e93\u64cd\u4f5c\u7b49\u7b49\u90fd\u5e94\u8be5\u8bb0\u5f55\u8d77\u6765\uff0c\u90a3\u4e48\u8fd9\u4e9b\u65e5\u5fd7\u6211\u4eec\u79f0\u4e3a\u64cd\u4f5c\u65e5\u5fd7\uff0c\u4e5f\u53ef\u4ee5\u8bf4\u5ba1\u8ba1\u65e5\u5fd7\u3002"}),"\n",(0,t.jsx)(n.admonition,{title:"\u5173\u4e8e\u6570\u636e\u5e93\u64cd\u4f5c\u5ba1\u8ba1\u65e5\u5fd7",type:"tip",children:(0,t.jsxs)(n.p,{children:["\u5982\u9700\u5b9e\u73b0 ",(0,t.jsx)(n.code,{children:"sql"})," \u64cd\u4f5c\uff0c",(0,t.jsx)(n.code,{children:"\u6570\u636e\u5e93\u64cd\u4f5c"})," \u7684\u5ba1\u8ba1\u65e5\u5fd7\u53ef\u67e5\u9605 \u3010",(0,t.jsx)(n.a,{href:"/docs/dbcontext-audit",children:"9.23 \u5ba1\u8ba1\u65e5\u5fd7\u7ae0\u8282"}),"\u3011"]})}),"\n",(0,t.jsx)(n.h2,{id:"542-\u8bf7\u6c42\u5ba1\u8ba1\u65e5\u5fd7",children:"5.4.2 \u8bf7\u6c42\u5ba1\u8ba1\u65e5\u5fd7"}),"\n",(0,t.jsx)(n.admonition,{title:"\u5b9e\u73b0\u539f\u7406",type:"note",children:(0,t.jsxs)(n.p,{children:["\u5728\u8fd9\u91cc\uff0c\u7ed3\u5408 \u3010",(0,t.jsx)(n.a,{href:"/docs/filter",children:"5.3 \u7b5b\u9009\u5668"}),"\u3011 \u5b9e\u73b0\u8bf7\u6c42\u5ba1\u8ba1\u65e5\u5fd7\u529f\u80fd\u3002"]})}),"\n",(0,t.jsxs)(n.p,{children:["\u8bf7\u6c42\u5ba1\u8ba1\u65e5\u5fd7\u901a\u5e38\u6307\u7684\u662f\u8bb0\u5f55\u8bf7\u6c42\u5730\u5740\uff0c\u6765\u6e90\u5730\u5740\uff0c\u64cd\u4f5c\u4eba\uff0c\u4f20\u9012\u53c2\u6570\u7b49\u3002\u8fd9\u4e2a\u4e3b\u8981\u662f\u901a\u8fc7 ",(0,t.jsx)(n.code,{children:"IAsyncActionFilter"})," \u7b5b\u9009\u5668\u5b9e\u73b0\uff0c\u5982\uff1a"]}),"\n",(0,t.jsxs)(n.ol,{children:["\n",(0,t.jsxs)(n.li,{children:["\u5b9a\u4e49 ",(0,t.jsx)(n.code,{children:"RequestAuditFilter"})," \u5e76\u5b9e\u73b0 ",(0,t.jsx)(n.code,{children:"IAsyncActionFilter"})]}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers {9,45}",children:'using Microsoft.AspNetCore.Http;\r\nusing Microsoft.AspNetCore.Mvc.Filters;\r\nusing System;\r\nusing System.Security.Claims;\r\nusing System.Threading.Tasks;\r\n\r\nnamespace Furion.Web.Core\r\n{\r\n public class RequestAuditFilter : IAsyncActionFilter\r\n {\r\n public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)\r\n {\r\n //============== \u8fd9\u91cc\u662f\u6267\u884c\u65b9\u6cd5\u4e4b\u524d\u83b7\u53d6\u6570\u636e ====================\r\n\r\n // \u83b7\u53d6\u63a7\u5236\u5668\u3001\u8def\u7531\u4fe1\u606f\r\n var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;\r\n\r\n // \u83b7\u53d6\u8bf7\u6c42\u7684\u65b9\u6cd5\r\n var method = actionDescriptor.MethodInfo;\r\n\r\n // \u83b7\u53d6 HttpContext \u548c HttpRequest \u5bf9\u8c61\r\n var httpContext = context.HttpContext;\r\n var httpRequest = httpContext.Request;\r\n\r\n // \u83b7\u53d6\u5ba2\u6237\u7aef Ipv4 \u5730\u5740\r\n var remoteIPv4 = httpContext.GetRemoteIpAddressToIPv4();\r\n\r\n // \u83b7\u53d6\u8bf7\u6c42\u7684 Url \u5730\u5740\r\n var requestUrl = httpRequest.GetRequestUrlAddress();\r\n\r\n // \u83b7\u53d6\u6765\u6e90 Url \u5730\u5740\r\n var refererUrl = httpRequest.GetRefererUrlAddress();\r\n\r\n // \u83b7\u53d6\u8bf7\u6c42\u53c2\u6570\uff08\u5199\u5165\u65e5\u5fd7\uff0c\u9700\u5e8f\u5217\u5316\u6210\u5b57\u7b26\u4e32\u540e\u5b58\u50a8\uff09\r\n var parameters = context.ActionArguments;\r\n\r\n // \u83b7\u53d6\u64cd\u4f5c\u4eba\uff08\u5fc5\u987b\u6388\u6743\u8bbf\u95ee\u624d\u6709\u503c\uff09"userId" \u4e3a\u4f60\u5b58\u50a8\u7684 claims type\uff0cjwt \u6388\u6743\u5bf9\u5e94\u7684\u662f payload \u4e2d\u5b58\u50a8\u7684\u952e\u540d\r\n var userId = httpContext.User?.FindFirstValue("userId");\r\n\r\n // \u8bf7\u6c42\u65f6\u95f4\r\n var requestedTime = DateTimeOffset.Now;\r\n\r\n\r\n //============== \u8fd9\u91cc\u662f\u6267\u884c\u65b9\u6cd5\u4e4b\u540e\u83b7\u53d6\u6570\u636e ====================\r\n var actionContext = await next();\r\n\r\n // \u83b7\u53d6\u8fd4\u56de\u7684\u7ed3\u679c\r\n var returnResult = actionContext.Result;\r\n\r\n // \u5224\u65ad\u662f\u5426\u8bf7\u6c42\u6210\u529f\uff0c\u6ca1\u6709\u5f02\u5e38\u5c31\u662f\u8bf7\u6c42\u6210\u529f\r\n var isRequestSucceed = actionContext.Exception == null;\r\n\r\n // \u83b7\u53d6\u8c03\u7528\u5806\u6808\u4fe1\u606f\uff0c\u63d0\u4f9b\u66f4\u52a0\u7b80\u5355\u660e\u4e86\u7684\u8c03\u7528\u548c\u5f02\u5e38\u5806\u6808\r\n var stackTrace = EnhancedStackTrace.Current();\r\n\r\n // \u8fd9\u91cc\u5199\u5165\u65e5\u5fd7\uff0c\u6216\u5b58\u50a8\u5230\u6570\u636e\u5e93\u4e2d\uff01\uff01\uff01~~~~~~~~~~~~~~~~~~~~\r\n }\r\n }\r\n}\n'})}),"\n",(0,t.jsxs)(n.ol,{start:"2",children:["\n",(0,t.jsxs)(n.li,{children:["\u6ce8\u518c ",(0,t.jsx)(n.code,{children:"RequestAuditFilter"})," \u7b5b\u9009\u5668"]}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-cs",metastring:"showLineNumbers",children:"services.AddMvcFilter<RequestAuditFilter>();\n"})}),"\n",(0,t.jsxs)(n.h2,{id:"543-loggingmonitor-\u5ba1\u8ba1\u65e5\u5fd7",children:["5.4.3 ",(0,t.jsx)(n.code,{children:"LoggingMonitor"})," \u5ba1\u8ba1\u65e5\u5fd7"]}),"\n",(0,t.jsx)(n.admonition,{title:"\u5c0f\u77e5\u8bc6",type:"tip",children:(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"Furion"})," \u63d0\u4f9b\u4e86\u975e\u5e38\u5f3a\u5927\u7684 ",(0,t.jsx)(n.code,{children:"LoggingMonitor"})," \u5ba1\u8ba1\u65e5\u5fd7\u529f\u80fd\uff0c\u53ef\u76f4\u63a5\u4f7f\u7528\uff1a",(0,t.jsx)(n.a,{href:"/docs/logging#1811-loggingmonitor-%E7%9B%91%E5%90%AC%E6%97%A5%E5%BF%97",children:"LoggingMonitor \u6587\u6863"})]})}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",metastring:"showLineNumbers",children:'\u250f\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 Logging Monitor \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\r\n\u2523 Furion.Application.TestLoggerServices.GetPerson (Furion.Application)\r\n\u2523\r\n\u2523 \u63a7\u5236\u5668\u540d\u79f0\uff1a TestLoggerServices\r\n\u2523 \u64cd\u4f5c\u540d\u79f0\uff1a GetPerson\r\n\u2523 \u8def\u7531\u4fe1\u606f\uff1a [area]: ; [controller]: test-logger; [action]: person\r\n\u2523 \u8bf7\u6c42\u65b9\u5f0f\uff1a POST\r\n\u2523 \u8bf7\u6c42\u5730\u5740\uff1a https://localhost:44316/api/test-logger/person/11\r\n\u2523 \u6765\u6e90\u5730\u5740\uff1a https://localhost:44316/api/index.html\r\n\u2523 \u6d4f\u89c8\u5668\u6807\u8bc6\uff1a Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.62\r\n\u2523 \u5ba2\u6237\u7aef IP \u5730\u5740\uff1a 0.0.0.1\r\n\u2523 \u670d\u52a1\u7aef IP \u5730\u5740\uff1a 0.0.0.1\r\n\u2523 \u670d\u52a1\u7aef\u8fd0\u884c\u73af\u5883\uff1a Development\r\n\u2523 \u6267\u884c\u8017\u65f6\uff1a 31ms\r\n\u2523 \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 \u6388\u6743\u4fe1\u606f \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\r\n\u2523 JWT Token\uff1a Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjEsIkFjY291bnQiOiJhZG1pbiIsImlhdCI6MTY1ODcxNjc5NywibmJmIjoxNjU4NzE2Nzk3LCJleHAiOjE2NTg3MTc5OTcsImlzcyI6ImRvdG5ldGNoaW5hIiwiYXVkIjoicG93ZXJieSBGdXJpb24ifQ.VYZkwwqCwlUy3aJjuL-og62I0rkxNQ96kSjEm3VgXtg\r\n\u2523\r\n\u2523 UserId (integer)\uff1a 1\r\n\u2523 Account (string)\uff1a admin\r\n\u2523 iat (integer)\uff1a 1658716797\r\n\u2523 nbf (integer)\uff1a 1658716797\r\n\u2523 exp (integer)\uff1a 1658717997\r\n\u2523 iss (string)\uff1a dotnetchina\r\n\u2523 aud (string)\uff1a powerby Furion\r\n\u2523 \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 \u53c2\u6570\u5217\u8868 \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\r\n\u2523 Content-Type\uff1a\r\n\u2523\r\n\u2523 id (Int32)\uff1a 11\r\n\u2523 \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 \u8fd4\u56de\u4fe1\u606f \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\r\n\u2523 \u7c7b\u578b\uff1a Furion.Application.Persons.PersonDto\r\n\u2523 \u8fd4\u56de\u503c\uff1a {"Id":11,"Name":null,"Age":0,"Address":null,"PhoneNumber":null,"QQ":null,"CreatedTime":"0001-01-01T00:00:00+00:00","Childrens":null,"Posts":null}\r\n\u2517\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 Logging Monitor \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n'})}),"\n",(0,t.jsx)(n.h2,{id:"544-\u53cd\u9988\u4e0e\u5efa\u8bae",children:"5.4.4 \u53cd\u9988\u4e0e\u5efa\u8bae"}),"\n",(0,t.jsx)(n.admonition,{title:"\u4e0e\u6211\u4eec\u4ea4\u6d41",type:"note",children:(0,t.jsxs)(n.p,{children:["\u7ed9 Furion \u63d0 ",(0,t.jsx)(n.a,{href:"https://gitee.com/dotnetchina/Furion/issues/new?issue",children:"Issue"}),"\u3002"]})})]})}function u(e={}){const{wrapper:n}={...(0,i.a)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(a,{...e})}):a(e)}},1151:(e,n,r)=>{r.d(n,{Z:()=>c,a:()=>s});var t=r(7294);const i={},o=t.createContext(i);function s(e){const n=t.useContext(o);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),t.createElement(o.Provider,{value:n},e.children)}}}]); |