Skip to content

Commit

Permalink
Adds Logging Extensions to Log Project
Browse files Browse the repository at this point in the history
  • Loading branch information
Chingling152 committed Feb 29, 2024
1 parent f5ceb9e commit 4812845
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.Extensions.DependencyInjection;

namespace FinancialHub.Core.Infra.Logs.Extensions.Configurations
{
public static class IServiceCollectionExtensions
{
public static IServiceCollection AddCoreLogging(this IServiceCollection services)
{
services.AddLogging();
return services;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
</PropertyGroup>

<ItemGroup>
<Folder Include="Extensions\" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using FinancialHub.Core.Infra.Logs.Extensions.Configurations;

namespace FinancialHub.Core.WebApi.Extensions.Configurations
{
Expand All @@ -15,12 +16,29 @@ public static IServiceCollection AddApiConfigurations(this IServiceCollection se
config.ReportApiVersions = true;
});

return services;
}

public static IServiceCollection AddApiDocs(this IServiceCollection services)
{
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Financial Hub WebApi", Version = "v1" });
});

return services;
}

public static IServiceCollection AddApiLogging(this IServiceCollection services)
{
services
.AddCoreLogging();
services
.AddHttpLogging(logging =>
{
logging.LoggingFields = Microsoft.AspNetCore.HttpLogging.HttpLoggingFields.All;
});
return services;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ItemGroup>
<ProjectReference Include="..\FinancialHub.Core.Application\FinancialHub.Core.Application.csproj" />
<ProjectReference Include="..\FinancialHub.Core.Infra.Data\FinancialHub.Core.Infra.Data.csproj" />
<ProjectReference Include="..\FinancialHub.Core.Infra.Logs\FinancialHub.Core.Infra.Logs.csproj" />
<ProjectReference Include="..\FinancialHub.Core.Infra\FinancialHub.Core.Infra.csproj" />
<ProjectReference Include="..\FinancialHub.Core.Resources\FinancialHub.Core.Resources.csproj" />
</ItemGroup>
Expand Down
7 changes: 7 additions & 0 deletions src/api/core/FinancialHub.Core.WebApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public Startup(IConfiguration configuration)
public void ConfigureServices(IServiceCollection services)
{
services.AddApiConfigurations();
services.AddApiDocs();
services.AddApiLogging();

services.AddHttpLogging(logging =>
{
logging.LoggingFields = Microsoft.AspNetCore.HttpLogging.HttpLoggingFields.All;
});

services.AddCoreResources();
services.AddCoreServices();
Expand Down

0 comments on commit 4812845

Please sign in to comment.