Skip to content

Commit c95119e

Browse files
committed
Merge branch 'net6.0' of https://github.com/dodyg/practical-aspnetcore into net6.0
2 parents 3274b37 + 9f15022 commit c95119e

File tree

14 files changed

+124
-29
lines changed

14 files changed

+124
-29
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Samples for ASP.NET Core 6.0, 7.0 and 8.0 RC 1 (496)
1+
# Samples for ASP.NET Core 6.0, 7.0 and 8.0 RC 1 (497)
22

33
- Samples for ASP.NET Core **8.0 RC 1** is available [here](/projects/.net8) (34).
44
- Samples for ASP.NET Core **7.0** is available [here](/projects/.net7) (45).
@@ -30,7 +30,7 @@ Greetings from Cairo, Egypt. You can [sponsor](https://github.com/sponsors/dodyg
3030
| [Health Check](/projects/health-check) | 6 | |
3131
| [IHttpClientFactory](/projects/httpclientfactory) | 4 | |
3232
| [IHostedService](/projects/ihosted-service) | 2 | |
33-
| [Logging](/projects/logging) | 3 | |
33+
| [Logging](/projects/logging) | 4 | |
3434
| [Localization and Globalization](/projects/localization) | 6 | |
3535
| [Middleware](/projects/middleware) | 14 | |
3636
| [Mini Apps](/projects/mini) | 2 | |

projects/.net7/grpc-13/grpc-server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1111
</PackageReference>
1212
<PackageReference Include="Google.Protobuf" Version="3.21.6" />
13-
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.49.0" />
13+
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.52.0" />
1414
<PackageReference Include="Microsoft.AspNetCore.Grpc.JsonTranscoding" Version="7.0.0" />
1515
</ItemGroup>
1616
<ItemGroup>

projects/.net7/grpc-14/grpc-server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1111
</PackageReference>
1212
<PackageReference Include="Google.Protobuf" Version="3.21.6" />
13-
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.49.0" />
13+
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.52.0" />
1414
<PackageReference Include="Microsoft.AspNetCore.Grpc.JsonTranscoding" Version="7.0.0" />
1515
</ItemGroup>
1616
<ItemGroup>

projects/.net7/grpc-15/grpc-server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1111
</PackageReference>
1212
<PackageReference Include="Google.Protobuf" Version="3.21.6" />
13-
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.49.0" />
13+
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.52.0" />
1414
<PackageReference Include="Microsoft.AspNetCore.Grpc.JsonTranscoding" Version="7.0.0" />
1515
</ItemGroup>
1616
<ItemGroup>

projects/.net7/grpc-16/grpc-server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1111
</PackageReference>
1212
<PackageReference Include="Google.Protobuf" Version="3.21.6" />
13-
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.49.0" />
13+
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.52.0" />
1414
<PackageReference Include="Microsoft.AspNetCore.Grpc.JsonTranscoding" Version="7.0.0" />
1515
</ItemGroup>
1616
<ItemGroup>

projects/.net7/grpc-17/grpc-server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1111
</PackageReference>
1212
<PackageReference Include="Google.Protobuf" Version="3.21.6" />
13-
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.49.0" />
13+
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.52.0" />
1414
<PackageReference Include="Microsoft.AspNetCore.Grpc.JsonTranscoding" Version="7.0.0" />
1515
</ItemGroup>
1616
<ItemGroup>

projects/caching/caching-4/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
app.Run(async context =>
2525
{
26+
if (context.Request.Path == "/favicon.ico") return;//skip favicon request
27+
2628
var log = context.RequestServices.GetService<ILoggerFactory>().CreateLogger("app");
2729
var cache = context.RequestServices.GetService<IMemoryCache>();
2830
var greeting = cache.Get(CACHE_KEY) as string;

projects/logging/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Logging (3)
1+
# Logging (4)
22

33
* [Basic Logging](/projects/logging/logging-1)
44

@@ -12,4 +12,8 @@
1212

1313
This example shows how to display log to console in structured JSON logs.
1414

15+
* [Logging to Grafana Loki](/projects/logging/logging-Loki)
16+
17+
This example shows how to log to [Grafana Loki](https://grafana.com/oss/loki/).
18+
1519
dotnet6
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using LokiLoggingProvider.Options;
2+
3+
var builder = WebApplication.CreateBuilder(args);
4+
5+
builder.Logging.AddLoki(configure =>
6+
{
7+
configure.Client = PushClient.Grpc;
8+
configure.StaticLabels.JobName = "LokiWebApplication";
9+
});
10+
11+
var app = builder.Build();
12+
13+
app.MapGet("/test", (ILoggerFactory loggerFactory) =>
14+
{
15+
var logger = loggerFactory.CreateLogger("Start");
16+
logger.LogTrace("Trace message");
17+
logger.LogDebug("Debug message");
18+
logger.LogInformation("Information message");
19+
logger.LogWarning("Warning message");
20+
logger.LogError("Error message");
21+
logger.LogCritical("Critical message");
22+
return "OK";
23+
});
24+
25+
app.Run();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Log into Grafana Loki
2+
3+
This example shows how to log to [Grafana Loki](https://grafana.com/oss/loki/). The Docker is used for the software hosting.
4+
5+
- open a command-line window in the folder and execute:
6+
7+
```sh
8+
docker compose up
9+
```
10+
- make sure that [Grafana Loki](https://grafana.com/oss/loki/) and [Grafana Dashboard](https://grafana.com/grafana/) containers are succesfully installed
11+
- Compile and run the application
12+
```sh
13+
dotnet build
14+
dotnet run
15+
```
16+
- Navigate to /test endpoint. The response should be 'OK'. The console window should contain **info**, **warn**, **fail** and **crit** log messages.
17+
- Navigate in a browser to the Grafana Dashboard website: <http://localhost:3000/>
18+
- Add a loki data source <http://loki:3100>
19+
- Go to the 'Explore data' page and add Label filter: ``job="LokiWebApplication"``. Press the 'Run query' button
20+
- Log messages should be shown

0 commit comments

Comments
 (0)