Skip to content

Commit

Permalink
fixing hangfire logs
Browse files Browse the repository at this point in the history
  • Loading branch information
joaofx committed Feb 29, 2024
1 parent b6cff24 commit b013f3e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
2 changes: 0 additions & 2 deletions src/Miru.Redis/RedisRegistry.cs
@@ -1,6 +1,4 @@
using System;
using Hangfire;
using Hangfire.Redis;
using Hangfire.Redis.StackExchange;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand Down
20 changes: 19 additions & 1 deletion src/Miru.Testing/StorageTestServiceCollectionExtensions.cs
Expand Up @@ -22,11 +22,29 @@ public static IServiceCollection AddAppTestStorage(this IServiceCollection servi
return services.AddAppStorage<AppTestStorage>();
}

public static FormFile FormFile2(
this ITestFixture fixture,
string fileName,
string fileContent,
string contentType = null)
{
var path = fixture.AppStorage().Temp() / fileName;

if (contentType is null)
contentType = MimeTypes.MimeTypeMap.GetMimeType(path.FileExtension());

path.Dir().EnsureDirExist();

File.WriteAllText(path, fileContent);

return fixture.FormFile(path, contentType);
}

public static FormFile FormFile(this ITestFixture fixture, MiruPath path, string contentType)
{
var stream = File.OpenRead(path);

var file = new FormFile(stream, 0, stream.Length, null, System.IO.Path.GetFileName(path))
var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(path))
{
Headers = new HeaderDictionary(),
ContentType = contentType
Expand Down
1 change: 1 addition & 0 deletions src/Miru/MiruServiceCollectionExtensions.cs
Expand Up @@ -33,6 +33,7 @@ public static class MiruServiceCollectionExtensions
services.AddSerilogConfig(config =>
{
config.MinimumLevel.Override(typeof(TStartup).Assembly.GetName().Name, LogEventLevel.Information);
config.MinimumLevel.Override("Hangfire", LogEventLevel.Error);
});

services.AddFlashMessage();
Expand Down
16 changes: 9 additions & 7 deletions src/Miru/QueueingRegistry.cs
Expand Up @@ -26,13 +26,15 @@ public static class QueueingRegistry
// .UseConsole registers routes into hangfire dashboard statically
// So in automated tests, when queue is registered in different ServiceProvider
// instances, UseConsole unfairly throws InvalidOperationException
try
{
configuration.UseColouredConsoleLogProvider();
}
catch (InvalidOperationException)
{
}
// try
// {
// configuration
// .UseSerilogLogProvider()
// .UseColouredConsoleLogProvider();
// }
// catch (InvalidOperationException)
// {
// }
queuingBuilder?.Invoke(builder);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/Miru.Tests/Queuing/QueueingTest.cs
Expand Up @@ -25,7 +25,7 @@ public override IServiceCollection ConfigureServices(IServiceCollection services
.AddSingleton<BackgroundJobServer>()
.AddSerilogConfig(x =>
{
x.MinimumLevel.Information();
x.MinimumLevel.Fatal();
x.WriteToTestConsole();
});
}
Expand Down

0 comments on commit b013f3e

Please sign in to comment.