Event and error logging in Asp.net MVC 5 project -
i looking @ implementing logging mechanism in site of mine, wish basic user action logging. don't want log every single button click on, want log actions makes changes.
are there libraries or articles / tutorials out there can me implement , efficient logging mechanism asp.net site. im not sure if there changes in mvc5 might come in use logging know user authentication , authorization has changed fair amount 4 5.
i'm sure there dynamic library out there work in many different situations.
nice haves:
- async capability
- scalable
- simple use
i'm thinking along lines of creating custom filter or attribute logs suers action, that's idea, im here ask standard / industry way is.
there isn't industry standard. i've used filters or i've overridden "onactionexecuting" method on base controller class record controller / action events.
edit ::
trying more helpful vague. if you're worried errors , things use elmah. other logging use nlog or log4net.
if you're trying logging auditing or can use combination of those, or custom. in site created table stores every click on site creating object sort of :
public class audit { public int id { get; set; } public datetime auditdate { get; set; } public string controllername { get; set; } public string actionname { get; set; } public dictionary<string, object> values }
in base constructor, overrode onactionexecuting event :
protected override void onactionexecuting(actionexecutingcontext ctx) { checkforlogging(ctx); //do not omit line base.onactionexecuting(ctx); }
lets want log requests using new audit object
private void checkforlogging(actionexecutingcontext ctx) { //we leave logging of posts actual methods because they're more complex... if (ctx.httpcontext.request.requesttype == "get") { logging(ctx.actiondescriptor.actionname, ctx.actiondescriptor.controllerdescriptor.controllername, ctx.actionparameters); } }
thats info need fill logging object action name, controller name , params passed method. can either save db, or logfile or whatever want really.
the point pretty big thing. 1 way , may or may not you. maybe define bit more want log , when want it?
you can create custom attribute , decorate methods , check if attribute present when onactionexecuting method fires. can filter if present , read , use drive logging if want...
Comments
Post a Comment