| 12345678910111213141516171819202122232425262728293031 |
- using System.Diagnostics;
- using SHJX.Service.Common.Logging;
- using Microsoft.Extensions.Logging;
- using Unity.Interception.PolicyInjection.Pipeline;
- namespace SHJX.Service.Common.Interceptor.Handlers
- {
- [DebuggerStepThrough]
- public class LogHandler : ICallHandler
- {
- public int Order { get; set; }
- private static readonly ILogger logger = LogFactory.BuildLogger(typeof(LogHandler));
- public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
- {
- logger.LogInformation("-------------Method Excute Befored-------------");
- logger.LogInformation($"Method Name:{input.MethodBase.Name}");
- if (input.Arguments.Count > 0)
- {
- logger.LogInformation("Arguments:");
- for (int i = 0; i < input.Arguments.Count; i++)
- {
- logger.LogInformation($"parameterName:{input.Arguments.ParameterName(i)},parameterValue:{input.Arguments[i]}");
- }
- }
- var methodReturn = getNext()(input, getNext);
- logger.LogInformation("-------------Method Excute After-------------");
- logger.LogInformation(methodReturn.Exception is not null ? $"Exception:{methodReturn.Exception.Message} \n" : $"Excuted Successed \n");
- return methodReturn;
- }
- }
- }
|