diff --git a/.gitignore b/.gitignore
index 529fa551..7391825f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,8 +16,18 @@
# Mono auto generated files
mono_crash.*
+# JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
.idea/
-.vs/
+*.iml
+*.ipr
+*.iws
+out/
+.idea_modules/
+atlassian-ide-plugin.xml
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
# Build results
[Dd]ebug/
diff --git a/.idea/.idea.BMA.EHR.Solution/.idea/.name b/.idea/.idea.BMA.EHR.Solution/.idea/.name
deleted file mode 100644
index 888d8763..00000000
--- a/.idea/.idea.BMA.EHR.Solution/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-BMA.EHR.Solution
\ No newline at end of file
diff --git a/.idea/.idea.BMA.EHR.Solution/.idea/AndroidProjectSystem.xml b/.idea/.idea.BMA.EHR.Solution/.idea/AndroidProjectSystem.xml
deleted file mode 100644
index e82600c9..00000000
--- a/.idea/.idea.BMA.EHR.Solution/.idea/AndroidProjectSystem.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/.idea.BMA.EHR.Solution/.idea/aws.xml b/.idea/.idea.BMA.EHR.Solution/.idea/aws.xml
deleted file mode 100644
index b63b642c..00000000
--- a/.idea/.idea.BMA.EHR.Solution/.idea/aws.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/.idea.BMA.EHR.Solution/.idea/encodings.xml b/.idea/.idea.BMA.EHR.Solution/.idea/encodings.xml
deleted file mode 100644
index df87cf95..00000000
--- a/.idea/.idea.BMA.EHR.Solution/.idea/encodings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/.idea.BMA.EHR.Solution/.idea/indexLayout.xml b/.idea/.idea.BMA.EHR.Solution/.idea/indexLayout.xml
deleted file mode 100644
index 7b08163c..00000000
--- a/.idea/.idea.BMA.EHR.Solution/.idea/indexLayout.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/.idea.BMA.EHR.Solution/.idea/projectSettingsUpdater.xml b/.idea/.idea.BMA.EHR.Solution/.idea/projectSettingsUpdater.xml
deleted file mode 100644
index ef20cb08..00000000
--- a/.idea/.idea.BMA.EHR.Solution/.idea/projectSettingsUpdater.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/.idea.BMA.EHR.Solution/.idea/shelf/Uncommitted_changes_before_Merge_at_23_6_25_16_09_[Changes]/shelved.patch b/.idea/.idea.BMA.EHR.Solution/.idea/shelf/Uncommitted_changes_before_Merge_at_23_6_25_16_09_[Changes]/shelved.patch
deleted file mode 100644
index 96d6b3d9..00000000
--- a/.idea/.idea.BMA.EHR.Solution/.idea/shelf/Uncommitted_changes_before_Merge_at_23_6_25_16_09_[Changes]/shelved.patch
+++ /dev/null
@@ -1,67 +0,0 @@
-Index: .idea/.idea.BMA.EHR.Solution/.idea/workspace.xml
-IDEA additional info:
-Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
-<+>\n\n \n BMA.EHR.CheckInConsumer/BMA.EHR.CheckInConsumer.csproj\n BMA.EHR.CheckInConsumer/BMA.EHR.CheckInConsumer.csproj\n BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj\n BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj\n BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj\n BMA.EHR.Discipline.Service/BMA.EHR.Discipline.Service.csproj\n BMA.EHR.Discipline.Service/BMA.EHR.Discipline.Service.csproj\n BMA.EHR.Discipline.Service/BMA.EHR.Discipline.Service.csproj\n BMA.EHR.Insignia/BMA.EHR.Insignia.csproj\n BMA.EHR.Insignia/BMA.EHR.Insignia.csproj\n BMA.EHR.Insignia/BMA.EHR.Insignia.csproj\n BMA.EHR.Leave/BMA.EHR.Leave.csproj\n BMA.EHR.Leave/BMA.EHR.Leave.csproj\n BMA.EHR.Leave/BMA.EHR.Leave.csproj\n BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj\n BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj\n BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj\n BMA.EHR.OrganizationEmployee.Service/BMA.EHR.OrganizationEmployee.Service.csproj\n BMA.EHR.OrganizationEmployee.Service/BMA.EHR.OrganizationEmployee.Service.csproj\n BMA.EHR.OrganizationEmployee.Service/BMA.EHR.OrganizationEmployee.Service.csproj\n BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj\n BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj\n BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj\n BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj\n BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj\n BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj\n BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj\n BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj\n BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj\n BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj\n BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj\n LinkageResponseTest/LinkageResponseTest.csproj\n LinkageResponseTest/LinkageResponseTest.csproj\n \n \n \n \n \n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n {\n "customColor": "",\n "associatedIndex": 2\n}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n 1724638841465\n \n \n 1724638841465\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n file://$PROJECT_DIR$/BMA.EHR.Leave/Controllers/LeaveController.cs\n 1159\n \n \n \n \n \n \n \n \n \n \n \n \n \n
-Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
-<+>UTF-8
-===================================================================
-diff --git a/.idea/.idea.BMA.EHR.Solution/.idea/workspace.xml b/.idea/.idea.BMA.EHR.Solution/.idea/workspace.xml
---- a/.idea/.idea.BMA.EHR.Solution/.idea/workspace.xml (revision 27acadbb077eded5c9f01ce18df7d9a5ef9bfb63)
-+++ b/.idea/.idea.BMA.EHR.Solution/.idea/workspace.xml (date 1750669762540)
-@@ -66,22 +66,22 @@
-
-
-
-- {
-+ "keyToString": {
-+ ".NET Launch Settings Profile.BMA.EHR.Leave: https.executor": "Debug",
-+ ".NET Launch Settings Profile.BMA.EHR.Placement.Service: http.executor": "Run",
-+ "RunOnceActivity.ShowReadmeOnStart": "true",
-+ "RunOnceActivity.git.unshallow": "true",
-+ "git-widget-placeholder": "develop",
-+ "node.js.detected.package.eslint": "true",
-+ "node.js.detected.package.tslint": "true",
-+ "node.js.selected.package.eslint": "(autodetect)",
-+ "node.js.selected.package.tslint": "(autodetect)",
-+ "nodejs_package_manager_path": "npm",
-+ "settings.editor.selected.configurable": "preferences.lookFeel",
-+ "vue.rearranger.settings.migration": "true"
- }
--}]]>
-+}
-
-
-
-Index: .idea/.idea.BMA.EHR.Solution/.idea/projectSettingsUpdater.xml
-IDEA additional info:
-Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
-<+>\n\n \n \n \n \n
-Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
-<+>UTF-8
-===================================================================
-diff --git a/.idea/.idea.BMA.EHR.Solution/.idea/projectSettingsUpdater.xml b/.idea/.idea.BMA.EHR.Solution/.idea/projectSettingsUpdater.xml
---- a/.idea/.idea.BMA.EHR.Solution/.idea/projectSettingsUpdater.xml (revision 27acadbb077eded5c9f01ce18df7d9a5ef9bfb63)
-+++ b/.idea/.idea.BMA.EHR.Solution/.idea/projectSettingsUpdater.xml (date 1750669762835)
-@@ -2,6 +2,7 @@
-
-
-
-+
-
-
-
-\ No newline at end of file
diff --git a/.idea/.idea.BMA.EHR.Solution/.idea/vcs.xml b/.idea/.idea.BMA.EHR.Solution/.idea/vcs.xml
deleted file mode 100644
index 35eb1ddf..00000000
--- a/.idea/.idea.BMA.EHR.Solution/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/.idea.BMA.EHR.Solution/.idea/workspace.xml b/.idea/.idea.BMA.EHR.Solution/.idea/workspace.xml
deleted file mode 100644
index 74b94d8b..00000000
--- a/.idea/.idea.BMA.EHR.Solution/.idea/workspace.xml
+++ /dev/null
@@ -1,598 +0,0 @@
-
-
-
- BMA.EHR.CheckInConsumer/BMA.EHR.CheckInConsumer.csproj
- BMA.EHR.CheckInConsumer/BMA.EHR.CheckInConsumer.csproj
- BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj
- BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj
- BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj
- BMA.EHR.Discipline.Service/BMA.EHR.Discipline.Service.csproj
- BMA.EHR.Discipline.Service/BMA.EHR.Discipline.Service.csproj
- BMA.EHR.Discipline.Service/BMA.EHR.Discipline.Service.csproj
- BMA.EHR.Insignia/BMA.EHR.Insignia.csproj
- BMA.EHR.Insignia/BMA.EHR.Insignia.csproj
- BMA.EHR.Insignia/BMA.EHR.Insignia.csproj
- BMA.EHR.Leave/BMA.EHR.Leave.csproj
- BMA.EHR.Leave/BMA.EHR.Leave.csproj
- BMA.EHR.Leave/BMA.EHR.Leave.csproj
- BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj
- BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj
- BMA.EHR.MetaData.Service/BMA.EHR.MetaData.Service.csproj
- BMA.EHR.OrganizationEmployee.Service/BMA.EHR.OrganizationEmployee.Service.csproj
- BMA.EHR.OrganizationEmployee.Service/BMA.EHR.OrganizationEmployee.Service.csproj
- BMA.EHR.OrganizationEmployee.Service/BMA.EHR.OrganizationEmployee.Service.csproj
- BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj
- BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj
- BMA.EHR.Placement.Service/BMA.EHR.Placement.Service.csproj
- BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj
- BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj
- BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj
- BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj
- BMA.EHR.Report.Service/BMA.EHR.Report.Service.csproj
- BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj
- BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj
- BMA.EHR.Retirement.Service/BMA.EHR.Retirement.Service.csproj
- LinkageResponseTest/LinkageResponseTest.csproj
- LinkageResponseTest/LinkageResponseTest.csproj
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {
- "customColor": "",
- "associatedIndex": 2
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1724638841465
-
-
- 1724638841465
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- file://$PROJECT_DIR$/BMA.EHR.Leave/Controllers/LeaveController.cs
- 1159
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/BMA.EHR.Command.Service/Program.cs b/BMA.EHR.Command.Service/Program.cs
index b9d846f4..ea76fb2b 100644
--- a/BMA.EHR.Command.Service/Program.cs
+++ b/BMA.EHR.Command.Service/Program.cs
@@ -115,12 +115,15 @@ var app = builder.Build();
app.UseHttpsRedirection();
app.UseCors();
+
+ app.UseMiddleware();
+
app.UseAuthentication();
app.UseAuthorization();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapControllers();
- app.UseMiddleware();
+
// apply migrations
//await using var scope = app.Services.CreateAsyncScope();
diff --git a/BMA.EHR.Discipline.Service/Program.cs b/BMA.EHR.Discipline.Service/Program.cs
index 4ead4ce6..5a1f99c4 100644
--- a/BMA.EHR.Discipline.Service/Program.cs
+++ b/BMA.EHR.Discipline.Service/Program.cs
@@ -148,13 +148,15 @@ var app = builder.Build();
app.UseHttpsRedirection();
app.UseCors();
+
+ app.UseMiddleware();
app.UseAuthentication();
app.UseAuthorization();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapControllers();
- app.UseMiddleware();
- app.UseMiddleware();
+ // app.UseMiddleware();
+ // app.UseMiddleware();
app.UseHangfireDashboard("/hangfire", new DashboardOptions()
{
diff --git a/BMA.EHR.Domain/Middlewares/CombinedErrorHandlerAndLoggingMiddleware.cs b/BMA.EHR.Domain/Middlewares/CombinedErrorHandlerAndLoggingMiddleware.cs
new file mode 100644
index 00000000..e806531f
--- /dev/null
+++ b/BMA.EHR.Domain/Middlewares/CombinedErrorHandlerAndLoggingMiddleware.cs
@@ -0,0 +1,550 @@
+using BMA.EHR.Domain.Common;
+using BMA.EHR.Domain.Shared;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Configuration;
+using Nest;
+using Newtonsoft.Json;
+using System.Diagnostics;
+using System.Net;
+using System.Net.Http.Headers;
+using System.Security.Claims;
+using System.Text.Encodings.Web;
+using System.Text.Json;
+using JsonSerializer = System.Text.Json.JsonSerializer;
+
+namespace BMA.EHR.Domain.Middlewares
+{
+ public class CombinedErrorHandlerAndLoggingMiddleware
+ {
+ private readonly RequestDelegate _next;
+ private readonly IConfiguration _configuration;
+
+ private string Uri = "";
+ private string IndexFormat = "";
+ private string SystemName = "";
+ private string APIKey = "";
+
+ public CombinedErrorHandlerAndLoggingMiddleware(RequestDelegate next, IConfiguration configuration)
+ {
+ _next = next;
+ _configuration = configuration;
+
+ Uri = _configuration["ElasticConfiguration:Uri"] ?? "http://192.168.1.40:9200";
+ IndexFormat = _configuration["ElasticConfiguration:IndexFormat"] ?? "bma-ehr-log-index";
+ SystemName = _configuration["ElasticConfiguration:SystemName"] ?? "Unknown";
+ }
+
+ public async Task Invoke(HttpContext context)
+ {
+ Console.WriteLine("=== CombinedErrorHandlerAndLoggingMiddleware Start ===");
+
+ var settings = new ConnectionSettings(new Uri(Uri))
+ .DefaultIndex(IndexFormat);
+ var client = new ElasticClient(settings);
+
+ var startTime = DateTime.UtcNow;
+ var stopwatch = Stopwatch.StartNew();
+ string? responseBodyJson = null;
+ string? requestBodyJson = null;
+ Exception? caughtException = null;
+
+ // อ่าน Request Body
+ string requestBody = await ReadRequestBodyAsync(context);
+ if (requestBody != "")
+ {
+ requestBodyJson = await FormatRequestBody(context, requestBody);
+ }
+
+ var originalBodyStream = context.Response.Body;
+
+ using (var memoryStream = new MemoryStream())
+ {
+ // เปลี่ยน stream ของ Response เพื่อให้สามารถอ่านได้
+ context.Response.Body = memoryStream;
+
+ var keycloakId = context.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? Guid.Empty.ToString("D");
+ var token = context.Request.Headers["Authorization"];
+ GetProfileByKeycloakIdLocal? pf = null;
+
+ try
+ {
+ pf = await GetProfileByKeycloakIdAsync(Guid.Parse(keycloakId), token);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Error getting profile: {ex.Message}");
+ }
+
+ try
+ {
+ await _next(context);
+ Console.WriteLine($"Request completed with status: {context.Response.StatusCode}");
+
+ // จัดการ response format หลังจาก request ผ่าน pipeline แล้ว
+ // รวมถึงการจัดการ 401/403 ที่มาจาก Authentication middleware
+ await FormatResponse(context, memoryStream);
+ }
+ catch (ObjectDisposedException)
+ {
+ Console.WriteLine("ObjectDisposedException caught in main Invoke");
+ caughtException = new ObjectDisposedException("Response");
+ return;
+ }
+ catch (OperationCanceledException)
+ {
+ Console.WriteLine("OperationCanceledException caught in main Invoke");
+ caughtException = new OperationCanceledException("Operation was cancelled");
+ return;
+ }
+ catch (Exception error)
+ {
+ Console.WriteLine($"Exception caught in main Invoke: {error.Message}");
+ caughtException = error;
+ // จัดการ exception และ format เป็น response
+ await FormatExceptionResponse(context, error, memoryStream);
+ }
+ finally
+ {
+ stopwatch.Stop();
+ await LogRequest(context, client, startTime, stopwatch, pf, keycloakId, requestBodyJson, memoryStream, caughtException);
+
+ // เขียนข้อมูลกลับไปยัง original Response body
+ if (memoryStream.Length > 0)
+ {
+ memoryStream.Seek(0, SeekOrigin.Begin);
+ await memoryStream.CopyToAsync(originalBodyStream);
+ }
+ }
+ }
+
+ Console.WriteLine("=== CombinedErrorHandlerAndLoggingMiddleware End ===");
+ }
+
+ private async Task FormatRequestBody(HttpContext context, string requestBody)
+ {
+ try
+ {
+ if (context.Request.HasFormContentType)
+ {
+ var form = await context.Request.ReadFormAsync();
+ var formData = new Dictionary();
+
+ foreach (var field in form)
+ {
+ formData[field.Key] = field.Value.ToString();
+ }
+
+ if (form.Files.Count > 0)
+ {
+ var fileDataList = new List