.NET Core应用程序中用于单元测试的模拟日志文件

问题描述

在C#应用程序中,我有一个getLogFile,可以通过调用GetLogFile()方法来设置:

private static string getLogFile = GetLogFile();

private static string GetLogFile()
{
    var fileTarget = (FileTarget)LogManager.Configuration.FindTargetByName("file-target");
    var logEventInfo = new LogEventInfo();
    string fileName = fileTarget.FileName.Render(logEventInfo);
    if (!File.Exists(fileName))
        throw new Exception("Log file does not exist.");
    return fileName;
}

我现在正在尝试对一些代码进行单元测试,这将需要设置getLogFile变量。我想以某种方式来模拟它,因为我想在测试中使用特定的日志数据,但是不确定如何去做。我该怎么办?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)