Adding test project Web
b712934450f8c74adce8f940143dfe907622be66
10 files changed
VanDerHeijden.Logging.slnxtests/VanDerHeijden.Logging.Web/Controllers/HomeController.cstests/VanDerHeijden.Logging.Web/Extensions/MongDbExtensions.cstests/VanDerHeijden.Logging.Web/Extensions/MongoDbLoggingExtensions.cstests/VanDerHeijden.Logging.Web/Program.cstests/VanDerHeijden.Logging.Web/Properties/launchSettings.jsontests/VanDerHeijden.Logging.Web/VanDerHeijden.Logging.Web.csprojtests/VanDerHeijden.Logging.Web/appsettings.Development.jsontests/VanDerHeijden.Logging.Web/appsettings.jsontests/VanDerHeijden.Logging.Web/wwwroot/Index.cshtml
diff --git a/VanDerHeijden.Logging.slnx b/VanDerHeijden.Logging.slnx
index e6ba402..735246c 100644
--- a/VanDerHeijden.Logging.slnx
+++ b/VanDerHeijden.Logging.slnx
@@ -1,8 +1,9 @@
<Solution>
- <Project Path="src/VanDerHeijden.Logging/VanDerHeijden.Logging.csproj" />
<Project Path="src/VanDerHeijden.Logging.File/VanDerHeijden.Logging.File.csproj" />
<Project Path="src/VanDerHeijden.Logging.MongoDb/VanDerHeijden.Logging.MongoDb.csproj" />
<Project Path="src/VanDerHeijden.Logging.Redis/VanDerHeijden.Logging.Redis.csproj" />
<Project Path="src/VanDerHeijden.Logging.Sql/VanDerHeijden.Logging.Sql.csproj" />
+ <Project Path="src/VanDerHeijden.Logging/VanDerHeijden.Logging.csproj" />
<Project Path="tests/VanDerHeijden.Logging.File.Benchmarks/VanDerHeijden.Logging.File.Benchmarks.csproj" />
+ <Project Path="tests/VanDerHeijden.Logging.Web/VanDerHeijden.Logging.Web.csproj" Id="ae1da180-d2c0-49e4-a792-43479aea21de" />
</Solution>
diff --git a/tests/VanDerHeijden.Logging.Web/Controllers/HomeController.cs b/tests/VanDerHeijden.Logging.Web/Controllers/HomeController.cs
new file mode 100644
index 0000000..a6c510e
--- /dev/null
+++ b/tests/VanDerHeijden.Logging.Web/Controllers/HomeController.cs
@@ -0,0 +1,11 @@
+using Microsoft.AspNetCore.Mvc;
+
+namespace VanDerHeijden.Logging.Web.Controllers;
+
+public class HomeController : Controller
+{
+ public IActionResult Index()
+ {
+ return View();
+ }
+}
diff --git a/tests/VanDerHeijden.Logging.Web/Extensions/MongDbExtensions.cs b/tests/VanDerHeijden.Logging.Web/Extensions/MongDbExtensions.cs
new file mode 100644
index 0000000..60d38a1
--- /dev/null
+++ b/tests/VanDerHeijden.Logging.Web/Extensions/MongDbExtensions.cs
@@ -0,0 +1,25 @@
+using MongoDB.Driver;
+
+namespace VanDerHeijden.Logging.Web.Extensions;
+
+public static class MongoDbDatabaseExtensions
+{
+ public static IServiceCollection AddMongoDbDatabase(this IServiceCollection services, IConfiguration configuration)
+ {
+ services.AddSingleton<IMongoClient>(sp =>
+ {
+ var settings = MongoClientSettings.FromConnectionString(configuration["ConnectionStrings:MongoDb"]);
+ settings.RetryWrites = true;
+ settings.RetryReads = true;
+ return new MongoClient(settings);
+ });
+
+ services.AddSingleton<IMongoDatabase>(sp =>
+ {
+ var client = sp.GetRequiredService<IMongoClient>();
+ return client.GetDatabase(configuration["MongoDb:DatabaseName"]);
+ });
+
+ return services;
+ }
+}
diff --git a/tests/VanDerHeijden.Logging.Web/Extensions/MongoDbLoggingExtensions.cs b/tests/VanDerHeijden.Logging.Web/Extensions/MongoDbLoggingExtensions.cs
new file mode 100644
index 0000000..9cda365
--- /dev/null
+++ b/tests/VanDerHeijden.Logging.Web/Extensions/MongoDbLoggingExtensions.cs
@@ -0,0 +1,26 @@
+using MongoDB.Driver;
+using VanDerHeijden.Logging.MongoDb;
+using VanDerHeijden.Logging.Web.Extensions;
+
+namespace VanDerHeijden.Logging.Web.Extensions;
+
+public static class MongoDbLoggingExtensions
+{
+ public static IServiceCollection AddMongoDbLogging(this IServiceCollection services, IConfiguration configuration)
+ {
+ services.AddHttpContextAccessor();
+
+ services.AddSingleton<IMongoCollection<LogEntry>>(sp =>
+ {
+ IMongoDatabase database = sp.GetRequiredService<IMongoDatabase>();
+ string collectioname = configuration["MongoDb:Collections:Logs"] ?? "Logs";
+ return database.GetCollection<LogEntry>(collectioname);
+ });
+
+ return services;
+ }
+
+ public static ILoggingBuilder AddMongoDbLogger(this ILoggingBuilder logging) =>
+ logging.AddMongoDbLogger(sp => sp.GetRequiredService<IMongoCollection<LogEntry>>());
+}
+
diff --git a/tests/VanDerHeijden.Logging.Web/Program.cs b/tests/VanDerHeijden.Logging.Web/Program.cs
new file mode 100644
index 0000000..2ea3af0
--- /dev/null
+++ b/tests/VanDerHeijden.Logging.Web/Program.cs
@@ -0,0 +1,51 @@
+using Microsoft.AspNetCore.Mvc.Razor;
+using System.Globalization;
+using VanDerHeijden.Logging;
+using VanDerHeijden.Logging.MongoDb;
+using VanDerHeijden.Logging.Web.Extensions;
+
+CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
+CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
+
+var builder = WebApplication.CreateBuilder(new WebApplicationOptions
+{
+ ContentRootPath = AppContext.BaseDirectory
+});
+var services = builder.Services;
+
+builder.Logging
+ .AddCustomLogger()
+ .AddMongoDbLogger();
+
+services.AddMongoDbDatabase(builder.Configuration);
+services.AddMongoDbLogging(builder.Configuration);
+
+services.AddControllersWithViews();
+
+services.AddRazorPages(o => o.RootDirectory = "/wwwroot");
+
+services.Configure<RazorViewEngineOptions>(options =>
+{
+ options.ViewLocationFormats.Add("/wwwroot/{0}.cshtml");
+});
+
+services.AddHttpContextAccessor();
+
+services.AddMvcCore();
+//services.AddJsonBodyProvider();
+
+var app = builder.Build();
+
+app.UseRouting();
+
+app.UseDefaultFiles();
+app.UseStaticFiles();
+app.UseDeveloperExceptionPage();
+
+app.MapControllers();
+app.MapDefaultControllerRoute();
+
+app.MapRazorPages();
+
+await app.RunAsync();
+
diff --git a/tests/VanDerHeijden.Logging.Web/Properties/launchSettings.json b/tests/VanDerHeijden.Logging.Web/Properties/launchSettings.json
new file mode 100644
index 0000000..afbbef4
--- /dev/null
+++ b/tests/VanDerHeijden.Logging.Web/Properties/launchSettings.json
@@ -0,0 +1,23 @@
+{
+ "$schema": "https://json.schemastore.org/launchsettings.json",
+ "profiles": {
+ "http": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "applicationUrl": "http://localhost:5290",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "https": {
+ "commandName": "Project",
+ "dotnetRunMessages": true,
+ "launchBrowser": true,
+ "applicationUrl": "https://localhost:7059;http://localhost:5290",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ }
+ }
+}
diff --git a/tests/VanDerHeijden.Logging.Web/VanDerHeijden.Logging.Web.csproj b/tests/VanDerHeijden.Logging.Web/VanDerHeijden.Logging.Web.csproj
new file mode 100644
index 0000000..458f07c
--- /dev/null
+++ b/tests/VanDerHeijden.Logging.Web/VanDerHeijden.Logging.Web.csproj
@@ -0,0 +1,13 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+ <PropertyGroup>
+ <TargetFramework>net10.0</TargetFramework>
+ <Nullable>enable</Nullable>
+ <ImplicitUsings>enable</ImplicitUsings>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\..\src\VanDerHeijden.Logging.MongoDb\VanDerHeijden.Logging.MongoDb.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/tests/VanDerHeijden.Logging.Web/appsettings.Development.json b/tests/VanDerHeijden.Logging.Web/appsettings.Development.json
new file mode 100644
index 0000000..0c208ae
--- /dev/null
+++ b/tests/VanDerHeijden.Logging.Web/appsettings.Development.json
@@ -0,0 +1,8 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ }
+}
diff --git a/tests/VanDerHeijden.Logging.Web/appsettings.json b/tests/VanDerHeijden.Logging.Web/appsettings.json
new file mode 100644
index 0000000..3acaf1a
--- /dev/null
+++ b/tests/VanDerHeijden.Logging.Web/appsettings.json
@@ -0,0 +1,21 @@
+{
+ "ConnectionStrings": {
+ "MongoDb": "mongodb://127.0.0.1:27017"
+ },
+ "MongoDb": {
+ "DatabaseName": "test1",
+ "IdleTimeoutInMinutes": 20,
+ "Collections": {
+ "Logs": "Logs"
+ }
+ },
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "AppWhatsApp.WhatsAppClient": "Debug",
+ "System.Net.Http.HttpClient": "None",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ },
+ "AllowedHosts": "*"
+}
diff --git a/tests/VanDerHeijden.Logging.Web/wwwroot/Index.cshtml b/tests/VanDerHeijden.Logging.Web/wwwroot/Index.cshtml
new file mode 100644
index 0000000..5e4e893
--- /dev/null
+++ b/tests/VanDerHeijden.Logging.Web/wwwroot/Index.cshtml
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8" />
+ <title></title>
+</head>
+<body>
+ View
+</body>
+</html>
\ No newline at end of file