Logging entry and exit of methods along with parameters automagically?

前端 未结 7 588
遇见更好的自我
遇见更好的自我 2021-01-02 04:31

Is there a way for me to add logging so that entering and exiting methods gets logged along with parameters automatically somehow for tracing purposes? How would I do so?

7条回答
  •  梦毁少年i
    2021-01-02 05:10

    This does not apply to all C# applications but I am doing the following in an Asp.Net Core application to add logging to controller method calls by implementing the following interfaces:

    IActionFilter, IAsyncActionFilter.

    public void OnActionExecuting(ActionExecutingContext context)    
    
    public void OnActionExecuted(ActionExecutedContext context)    
    
    public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)    
    

提交回复
热议问题