-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement NLog in unit test project #14347
Comments
Could you please ellaborate? |
Some exceptions during migration will not directly cause process interruption, but once an exception occurs, it will have a serious impact on the integrity of system functions Just like , the exception caused by the MySql /Postgresql syntax problem mentioned earlier did not interrupt the migration process It may be due to some considerations that the change exception is not thrown, but if we can also work with log file scanning to eliminate some errors that are not easy to find, it is also a good way And CI/CD will be able to find these errors automatically |
Just use below code . Maybe there should be a better way [Fact]
public async Task ValidateLogErrors()
{
using var context = new ScriptQueryContext();
//初始化测试环境
await context.InitializeAsync();
await context.UsingTenantScopeAsync(scope =>
{
var fileTarget = (FileTarget)LogManager.Configuration.FindTargetByName("file");
var logFilePath = fileTarget.FileName.Render(new LogEventInfo { TimeStamp = DateTime.Now });
Assert.True(File.Exists(logFilePath));
var hasError = AppFileHelper.ReadLines(logFilePath).Any(x => x.Contains("|ERROR|"));
Assert.False(hasError);
return Task.CompletedTask;
});
} |
Like a functional test to catch exceptions during setup that might get through otherwise. |
Currently, unit tests catch very limited exception information,
Many exceptions that occur during the installation process are ignored
Can I use the log function to quickly locate anomalies?
The text was updated successfully, but these errors were encountered: