How to test asp.net core built-in Ilogger

前端 未结 6 1509
无人共我
无人共我 2021-02-02 06:36

I want to verify some logs logged. I am using the asp.net core built-in ILogger, and inject it with the asp.net core built-in DI:

private readonly ILogger<         


        
6条回答
  •  [愿得一人]
    2021-02-02 07:24

    For those trying to receive a callback for the log calls:

                mock.Mock>()
                    .Setup(x =>
                        x.Log(
                            LogLevel.Information,
                            It.IsAny(),
                            It.IsAny(),
                            It.IsAny(),
                            (Func)It.IsAny()
                        )
                    )
                    .Callback(
                        (level, eventid, state, ex, func) =>
                        {
                            this.Out.WriteLine(state.ToString());
                        }
                    );
    
        

    提交回复
    热议问题