框架事件

以下这些框架事件,可用于一些特殊的扩展需求。



HttpClientEvent

public static class HttpClientEvent
{
    /// <summary>
    /// 创建Request对象前将会引发此事件
    /// </summary>
    public static event EventHandler<BeforeCreateRequestEventArgs> OnCreateRequest;
    
    /// <summary>
    /// 创建HttpWebRequest前将会引发此事件,提供最后一个修改请求参数的机会。
    /// </summary>
    public static event EventHandler<BeforeSendEventArgs> OnBeforeSendRequest;

    /// <summary>
    /// 表示请求完成时触发的事件
    /// </summary>
    public static event EventHandler<RequestFinishedEventArgs> OnRequestFinished;

等价的DiagnosticListener接口:

  • DiagnosticListener("ClownFish.HttpClientEvent")
    • OnBeforeSendRequest
    • OnRequestFinished



DbContextEvent

namespace ClownFish.Data;

public static class DbContextEvent
{
    /// <summary>
    /// 连接打开事件
    /// </summary>
    public static event EventHandler<OpenConnEventArgs> OnConnectionOpened;

    /// <summary>
    /// 命令执行之前事件
    /// </summary>
    public static event EventHandler<ExecuteCommandEventArgs> OnBeforeExecute;

    /// <summary>
    /// 命令执行之后事件
    /// </summary>
    public static event EventHandler<ExecuteCommandEventArgs> OnAfterExecute;

    /// <summary>
    /// 提交事务事件
    /// </summary>
    public static event EventHandler<CommitTransEventArgs> OnCommited;

等价的DiagnosticListener接口:

  • DiagnosticListener("ClownFish.DALEvent")
    • ConnectionOpened
    • BeforeExecute
    • AfterExecute
    • OnCommit



ClownFish.Log

public static class LogHelper
{
    /// <summary>
    /// 写日志时出现异常不能被处理时引用的事件
    /// </summary>
    public static event EventHandler<ExceptionEventArgs> OnError;
public static class FatalErrorLoger
{
    /// <summary>
    /// 当调用 LogException 方法时引发的事件,这表示有一个异常已发生。
    /// </summary>
    public static event EventHandler<ExceptionEventArgs> OnLogException;



RedisClientEvent

public static class RedisClientEvent
{
    /// <summary>
    /// 每当执行一次Redis调用后触发的事件
    /// </summary>
    public static event EventHandler<RedisClientEventArgs> OnExecuteFinished;



RedisClientEvent

public static class RabbitClientEvent
{
    /// <summary>
    /// 每次发送一条消息后触发
    /// </summary>
    public static event EventHandler<SendMessageEventArgs> OnSendMessage;