反射加异步,根据枚举值来异步执行方法:
protected delegate void AsyncWriteLogMsgEvent(string message);
protected delegate void AsyncWriteLogExceptionEvent(string message, Exception exception);
internal void Log(LogLevel level, string message)
{
Type thisType = this.GetType();
MethodInfo mi = thisType.GetMethod(SiteExtensions.GetEnumName(level));
if (mi == null || !mi.IsPublic || mi.IsStatic || mi.IsConstructor) return;
AsyncWriteLogMsgEvent writer = m => mi.Invoke(this, new object[] { m });
writer.BeginInvoke(message, null, null);
}
internal void Log(LogLevel level, string message, Exception exception)
{
Type thisType = this.GetType();
MethodInfo mi = thisType.GetMethod(SiteExtensions.GetEnumName(level));
if (mi == null || !mi.IsPublic || mi.IsStatic || mi.IsConstructor) return;
AsyncWriteLogExceptionEvent writer = (m, e) => mi.Invoke(this, new object[] {m, e});
writer.BeginInvoke(message, exception, null, null);
}
protected delegate void AsyncWriteLogExceptionEvent(string message, Exception exception);
internal void Log(LogLevel level, string message)
{
Type thisType = this.GetType();
MethodInfo mi = thisType.GetMethod(SiteExtensions.GetEnumName(level));
if (mi == null || !mi.IsPublic || mi.IsStatic || mi.IsConstructor) return;
AsyncWriteLogMsgEvent writer = m => mi.Invoke(this, new object[] { m });
writer.BeginInvoke(message, null, null);
}
internal void Log(LogLevel level, string message, Exception exception)
{
Type thisType = this.GetType();
MethodInfo mi = thisType.GetMethod(SiteExtensions.GetEnumName(level));
if (mi == null || !mi.IsPublic || mi.IsStatic || mi.IsConstructor) return;
AsyncWriteLogExceptionEvent writer = (m, e) => mi.Invoke(this, new object[] {m, e});
writer.BeginInvoke(message, exception, null, null);
}
浙公网安备 33010602011771号