Skip to content

Commit 98b4ecb

Browse files
packages added in centralized logging Sdk and GetAllErrorsResponseModel added and attached it with the api response
1 parent b72abf5 commit 98b4ecb

File tree

8 files changed

+73
-19
lines changed

8 files changed

+73
-19
lines changed

ApiIntegrationMvc/ApiIntegrationMvc.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10+
<ProjectReference Include="..\CentralizedLogging.Sdk\CentralizedLogging.Sdk.csproj" />
1011
<ProjectReference Include="..\UserManagement.Sdk\UserManagement.Sdk.csproj" />
1112
</ItemGroup>
1213

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CentralizedLogging.Contracts.Models
8+
{
9+
public class GetAllErrorsResponseModel
10+
{
11+
public long Id { get; set; }
12+
public string Severity { get; set; } = null!;
13+
public string Message { get; set; } = null!;
14+
public string? StackTrace { get; set; }
15+
public string? Source { get; set; }
16+
public string? UserId { get; set; }
17+
public string? RequestId { get; set; }
18+
public DateTime LoggedAt { get; set; }
19+
20+
// Instead of ApplicationId, expose the name
21+
public string ApplicationName { get; set; } = null!;
22+
}
23+
}

CentralizedLogging.Sdk/CentralizedLogging.Sdk.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
<ItemGroup>
1010
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.8" />
11+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.8" />
1112
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.8" />
13+
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.8" />
14+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.8" />
1215
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.8" />
1316
<PackageReference Include="Polly" Version="8.6.3" />
1417
<PackageReference Include="Polly.Extensions.Http" Version="3.0.0" />

CentralizedLogging.Sdk/Extensions/ServiceCollectionExtensions.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
using System;
2-
using Microsoft.Extensions.Configuration;
1+
using Microsoft.Extensions.Configuration;
32
using Microsoft.Extensions.DependencyInjection;
43
using Microsoft.Extensions.Options;
54
using Polly;
65
using CentralizedLogging.Sdk.Abstractions;
7-
using CentralizedLogging.Sdk.Auth;
86
using CentralizedLogging.Sdk.Configuration;
97

108

@@ -26,13 +24,7 @@ public static IServiceCollection AddUserManagementSdk(
2624
if (configure is not null)
2725
services.PostConfigure(configure);
2826

29-
// Delegating handler MUST be transient
30-
services.AddTransient<BearerTokenHandler>();
31-
32-
// Register the token provider (memory-based)
33-
services.AddScoped<IAccessTokenProvider, MemoryCacheAccessTokenProvider>();
34-
35-
27+
3628
// The Typed client
3729
services.AddHttpClient<ICentralizedLoggingClient, CentralizedLoggingClient>((sp, http) =>
3830
{
@@ -42,23 +34,22 @@ public static IServiceCollection AddUserManagementSdk(
4234

4335
http.BaseAddress = opts.BaseAddress;
4436
http.Timeout = opts.Timeout;
45-
})
46-
.AddHttpMessageHandler<BearerTokenHandler>()
37+
})
4738
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
4839
{
4940
// If you need custom certs, proxies, cookies, etc.
5041
UseCookies = false
5142
})
5243
.AddPolicyHandler((sp, req) =>
5344
{
54-
var opts = sp.GetRequiredService<IOptions<CentralizedLoggingOptions>().Value;
45+
var opts = sp.GetRequiredService<IOptions<CentralizedLoggingOptions>>().Value;
5546
return opts.EnableResiliencePolicies
5647
? HttpPolicies.GetRetryPolicy()
5748
: Polly.Policy.NoOpAsync().AsAsyncPolicy<HttpResponseMessage>();
5849
})
5950
.AddPolicyHandler((sp, req) =>
6051
{
61-
var opts = sp.GetRequiredService<IOptions<CentralizedLoggingOptions>().Value;
52+
var opts = sp.GetRequiredService<IOptions<CentralizedLoggingOptions>>().Value;
6253
return opts.EnableResiliencePolicies
6354
? HttpPolicies.GetCircuitBreakerPolicy()
6455
: Polly.Policy.NoOpAsync().AsAsyncPolicy<HttpResponseMessage>();

CentralizedLoggingApi/CentralizedLoggingApi.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@
3434
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="9.0.3" />
3535
</ItemGroup>
3636

37+
<ItemGroup>
38+
<ProjectReference Include="..\CentralizedLogging.Contracts\CentralizedLogging.Contracts.csproj" />
39+
</ItemGroup>
40+
3741
</Project>

CentralizedLoggingApi/Controllers/ErrorLogsController.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.AspNetCore.Authorization;
55
using Microsoft.AspNetCore.Mvc;
66
using Microsoft.EntityFrameworkCore;
7+
using CentralizedLogging.Contracts.Models;
78

89
namespace CentralizedLoggingApi.Controllers
910
{
@@ -66,12 +67,28 @@ public async Task<IActionResult> GetErrorById(long id)
6667
[HttpGet]
6768
public async Task<IActionResult> GetAllErrors()
6869
{
69-
var errors = await _context.ErrorLogs
70-
.Include(e => e.Application)
71-
.OrderByDescending(e => e.LoggedAt)
72-
.ToListAsync();
70+
//var errors = await _context.ErrorLogs
71+
// .Include(e => e.Application)
72+
// .OrderByDescending(e => e.LoggedAt)
73+
// .ToListAsync();
74+
75+
var logs = await _context.ErrorLogs
76+
.Include(e => e.Application)
77+
.Select(e => new GetAllErrorsResponseModel
78+
{
79+
Id = e.Id,
80+
Severity = e.Severity,
81+
Message = e.Message,
82+
StackTrace = e.StackTrace,
83+
Source = e.Source,
84+
UserId = e.UserId,
85+
RequestId = e.RequestId,
86+
LoggedAt = e.LoggedAt,
87+
ApplicationName = e.Application.Name // navigation property
88+
})
89+
.ToListAsync();
7390

74-
return Ok(errors);
91+
return Ok(logs);
7592
}
7693
}
7794
}

CentralizedLoggingMonitoring.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserManagement.Sdk", "UserM
1515
EndProject
1616
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CentralizedLogging.Sdk", "CentralizedLogging.Sdk\CentralizedLogging.Sdk.csproj", "{5DA73ABB-A410-4E63-A8B0-C55776CDC074}"
1717
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CentralizedLogging.Contracts", "CentralizedLogging.Contracts\CentralizedLogging.Contracts.csproj", "{FAAAA797-C668-4B08-B5CA-504A21A3917A}"
19+
EndProject
1820
Global
1921
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2022
Debug|Any CPU = Debug|Any CPU
@@ -45,6 +47,10 @@ Global
4547
{5DA73ABB-A410-4E63-A8B0-C55776CDC074}.Debug|Any CPU.Build.0 = Debug|Any CPU
4648
{5DA73ABB-A410-4E63-A8B0-C55776CDC074}.Release|Any CPU.ActiveCfg = Release|Any CPU
4749
{5DA73ABB-A410-4E63-A8B0-C55776CDC074}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{FAAAA797-C668-4B08-B5CA-504A21A3917A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{FAAAA797-C668-4B08-B5CA-504A21A3917A}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{FAAAA797-C668-4B08-B5CA-504A21A3917A}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{FAAAA797-C668-4B08-B5CA-504A21A3917A}.Release|Any CPU.Build.0 = Release|Any CPU
4854
EndGlobalSection
4955
GlobalSection(SolutionProperties) = preSolution
5056
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)