123456789101112131415161718192021222324252627282930 |
- using Castle.DynamicProxy;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Hotline.Settings.SystemLogDomain;
- public class LoggingInterceptor : IInterceptor
- {
- public void Intercept(IInvocation invocation)
- {
- // 检查方法是否有 LogAttribute
- var logAttribute = invocation.Method.GetCustomAttributes(typeof(LogToDatabaseAttribute), true)
- .FirstOrDefault() as LogToDatabaseAttribute;
- if (logAttribute != null)
- {
- Console.WriteLine($"[LOG] {logAttribute.Message}: {invocation.Method.Name}");
- }
- // 执行实际方法
- invocation.Proceed();
- if (logAttribute != null)
- {
- Console.WriteLine($"[LOG] Finished: {invocation.Method.Name}");
- }
- }
- }
|