Skip to content

Commit 3c33732

Browse files
Merge pull request #9 from Xebia-Migration-Training/feature/add-logging-middleware
2 parents 803473b + 9cc18c0 commit 3c33732

File tree

7 files changed

+117
-1
lines changed

7 files changed

+117
-1
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

labs/issues and pull requests.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# 2 Create a Project and a Sprint!
2+
3+
In this hands-on lab you will use GitHub's new Project experience to create a project to track issues and set up an agile style iterative process using sprints. Good luck! 👍
4+
5+
This hands on lab consists of the following steps:
6+
- [Create Issues in the repository](#create-issues-in-the-repository)
7+
- [Create a new Project](#create-a-new-project)
8+
- [Setup and view your sprint](#setup-and-view-your-sprint)
9+
10+
## Create Issues in the repository
11+
1. Work inside your current repository `https://github.com/Xebia-Migration-Training/ShippingApp.git`.
12+
2. Click `Issues`.
13+
3. Click `New issue` on the right hand side of the page.
14+
4. Enter a `Title`. Suggestion: `Create a login page`.
15+
5. Enter a comment in `Leave a comment`. Suggestion:
16+
```
17+
# My first Issue!
18+
- [ ] Create a login page for the website
19+
20+
```
21+
6. Create 3 more issues. Get creative and make them your own.
22+
23+
## Create a new Project
24+
1. Work inside your current repository `https://github.com/Xebia-Migration-Training/ShippingApp.git`.
25+
2. Click `Projects`.
26+
3. Click the down arrow next to `Link a project`.
27+
4. Select `New project`.
28+
5. Click `New project`.
29+
6. The `Select a template` dialog appears.
30+
7. Under `Project name` type your GitHub handle and then `my first project`. The title will look like `@<your-handle> my first project`.
31+
8. Verify `Table` is selected and click `Create`.
32+
9. Click `Add item from repository`.
33+
10. Select your repository from the drop-down list.
34+
11. Select the four issues your just created.
35+
12. Click `Add selected items`.
36+
37+
## Setup and view your sprint
38+
1. Click `New view, layout `Table`. This will be visible inside the project just created.
39+
2. Name the view `Sprint view`.
40+
3. Add a new field. Click the `+` sign next to the `Status` column.
41+
4. Click `New field` in the dialog box.
42+
5. Name the field `Sprint`.
43+
6. In the `Field type` select `Iteration`. Accept the defaults. You might have to rename the field to `Sprint` again.
44+
7. Click `Save and create`.
45+
8. Assign the first two Issues to `Sprint 1`.
46+
9. The third issue to `Sprint 2`.
47+
10. The fourth issue to `Sprint 3`.
48+
11. Under the `Sprint view` dropdown select `Group` then `Sprint`. The project should group by sprint.
49+
12. Save the changes to `Sprint view`.
50+
51+

scripts.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
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
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System.Diagnostics;
2+
3+
namespace ShippingRules.API.Middleware;
4+
5+
/// <summary>
6+
/// Middleware to log incoming HTTP requests and responses
7+
/// </summary>
8+
public class RequestLoggingMiddleware
9+
{
10+
private readonly RequestDelegate _next;
11+
private readonly ILogger<RequestLoggingMiddleware> _logger;
12+
13+
public RequestLoggingMiddleware(RequestDelegate next, ILogger<RequestLoggingMiddleware> logger)
14+
{
15+
_next = next;
16+
_logger = logger;
17+
}
18+
19+
public async Task InvokeAsync(HttpContext context)
20+
{
21+
var stopwatch = Stopwatch.StartNew();
22+
var requestId = Guid.NewGuid().ToString();
23+
24+
// Log request
25+
_logger.LogInformation(
26+
"Incoming Request: {RequestId} {Method} {Path} from {RemoteIp}",
27+
requestId,
28+
context.Request.Method,
29+
context.Request.Path,
30+
context.Connection.RemoteIpAddress
31+
);
32+
33+
try
34+
{
35+
await _next(context);
36+
}
37+
finally
38+
{
39+
stopwatch.Stop();
40+
41+
// Log response
42+
_logger.LogInformation(
43+
"Request Completed: {RequestId} {Method} {Path} responded {StatusCode} in {ElapsedMs}ms",
44+
requestId,
45+
context.Request.Method,
46+
context.Request.Path,
47+
context.Response.StatusCode,
48+
stopwatch.ElapsedMilliseconds
49+
);
50+
}
51+
}
52+
}
53+
54+
/// <summary>
55+
/// Extension method to register the logging middleware
56+
/// </summary>
57+
public static class RequestLoggingMiddlewareExtensions
58+
{
59+
public static IApplicationBuilder UseRequestLogging(this IApplicationBuilder builder)
60+
{
61+
return builder.UseMiddleware<RequestLoggingMiddleware>();
62+
}
63+
}

src/ShippingRules.API/ShippingRules.API.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />
1111
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
1212
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
13+
<!-- VULNERABLE DEPENDENCY FOR TESTING PURPOSES ONLY -->
14+
<!-- This package has known security vulnerabilities - DO NOT USE IN PRODUCTION -->
15+
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
1316
</ItemGroup>
1417

1518
<ItemGroup>

0 commit comments

Comments
 (0)