c# - Execute code before/after every controller action -


I have an ASP.NET MVC application for which I want to log events. I already have a log class with all the tools needed, but I have to close it immediately and close it (because this opens the file, so I can not depend on GC). My actions look like this:

  public performance menmanu () {CreateLog (); // Controller luggage log (message); // More Controller Accessories CloseLog (); See Return (MMDell); }   

or I can use the block by using , but this will be a little less intrusive and it will cause problems with exception handling. I've read about the action filter , which I could use to create and close my logs, but then there would be no way to reach the log object within the method.

Do you have any suggestions? How can I avoid repeating the code?

If other suggestions do not work or if you just need to do things other than logging Also, keep in mind that you can override the OnActionExecuting method (often in a base class for reuse).

  // Custom Controller Public Category Custom Controller: Controller {Secure Override On-Offing Connection (Action Accepting Contact Filter Context) {// Please be here ...} // Home Controller Public Classroom Home Controller: Custom Controller {// Action Methods Here ...}    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -