diff --git a/BMA.EHR.Recruit.Service.csproj b/BMA.EHR.Recruit.Service.csproj
index d2ebf6a..bd693de 100644
--- a/BMA.EHR.Recruit.Service.csproj
+++ b/BMA.EHR.Recruit.Service.csproj
@@ -25,6 +25,7 @@
+
diff --git a/Core/RequestLoggingMiddleware.cs b/Core/RequestLoggingMiddleware.cs
index d1796ec..8ffc72f 100644
--- a/Core/RequestLoggingMiddleware.cs
+++ b/Core/RequestLoggingMiddleware.cs
@@ -1,334 +1,247 @@
-using Microsoft.AspNetCore.Http;
-using Microsoft.Extensions.Configuration;
-using Nest;
-using Newtonsoft.Json;
-using System.Diagnostics;
-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.Recruit.Service.Core
-{
- public class RequestLoggingMiddleware
- {
- private readonly RequestDelegate _next;
- private readonly IConfiguration _configuration;
-
- private string Uri = "";
- private string IndexFormat = "";
- private string SystemName = "";
- private string APIKey = "";
-
- public RequestLoggingMiddleware(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";
- SystemName = "recruiting";
- }
-
- protected async Task GetExternalAPIAsync(string apiPath, string accessToken, string apiKey)
- {
- try
- {
- using (var client = new HttpClient())
- {
- // Set timeout to 30 seconds instead of default 100 seconds
- client.Timeout = TimeSpan.FromSeconds(30);
- client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Replace("Bearer ", ""));
- client.DefaultRequestHeaders.Add("api_key", apiKey);
-
- using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
- var _res = await client.GetAsync(apiPath, cts.Token);
- if (_res.IsSuccessStatusCode)
- {
- var _result = await _res.Content.ReadAsStringAsync();
- return _result;
- }
- return string.Empty;
- }
- }
- catch (TaskCanceledException)
- {
- // Log timeout but don't throw - return empty result instead
- Console.WriteLine($"API call timed out: {apiPath}");
- return string.Empty;
- }
- catch (Exception ex)
- {
- // Log other exceptions but don't throw - return empty result instead
- Console.WriteLine($"API call failed: {apiPath}, Error: {ex.Message}");
- return string.Empty;
- }
- }
-
- public async Task GetProfileByKeycloakIdAsync(Guid keycloakId, string? accessToken)
- {
- try
- {
- //var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak/{keycloakId}";
- var apiPath = $"{_configuration["API"]}/org/dotnet/user-logs/{keycloakId}";
- var apiKey = _configuration["API_KEY"] ?? "";
-
- var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
- if (!string.IsNullOrEmpty(apiResult))
- {
- var raw = JsonConvert.DeserializeObject(apiResult);
- if (raw != null)
- return raw.Result;
- }
-
- return null;
- }
- catch (Exception ex)
- {
- // Log exception but don't throw - return null instead
- Console.WriteLine($"GetProfileByKeycloakIdAsync failed for {keycloakId}: {ex.Message}");
- return null;
- }
- }
-
- public async Task Invoke(HttpContext context)
- {
- 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;
-
- string requestBody = await ReadRequestBodyAsync(context);
- if (requestBody != "")
- {
- if (context.Request.HasFormContentType)
- {
- var form = await context.Request.ReadFormAsync(); // อ่าน form-data
-
- var formData = new Dictionary();
- foreach (var field in form)
- {
- formData[field.Key] = field.Value.ToString();
- }
- // อ่านไฟล์ที่ถูกส่งมา (ถ้ามี)
- if (form.Files.Count > 0)
- {
- var fileDataList = new List