Logging zentral erweitert

This commit is contained in:
2026-06-01 13:24:54 +02:00
parent a0d06b16b5
commit 54f740af4c
3 changed files with 21 additions and 3 deletions

View File

@@ -59,6 +59,8 @@ namespace AICore.Facade
if (!response.Success)
{
_logger.Error($"GetAiPrompts: " + response.ToErrorString());
return null;
}

View File

@@ -2,6 +2,7 @@
using BS.Shared.DataContracts;
using BS.Shared.Exceptions;
using BS.Shared.Interface;
using log4net;
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
@@ -21,6 +22,8 @@ namespace BeWo.ServerUtils.ApiFacade
{
public class HttpClientFacade
{
private ILog _logger;
public HttpClientFacade(string base_url, string api_key, bool directConntect = true)
{
if (string.IsNullOrEmpty(base_url))
@@ -33,6 +36,8 @@ namespace BeWo.ServerUtils.ApiFacade
if (!string.IsNullOrWhiteSpace(api_key))
SetToken(api_key);
DirectConnect = directConntect;
_logger = LoggerUtils.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
}
public bool DirectConnect { get; private set; }
@@ -57,13 +62,16 @@ namespace BeWo.ServerUtils.ApiFacade
{
var http_response = await getResponseAsync(method).ConfigureAwait(false);
var json = await http_response.Content.ReadAsStringAsync().ConfigureAwait(false);
if (!http_response.IsSuccessStatusCode)
{
_logger.Error($"{http_response.ReasonPhrase} (Code:{http_response.StatusCode})");
_logger.Error(json);
return ApiResponse<T>.FailureResponse(AppError.ApiResponseFailed, http_response.ReasonPhrase, (int)http_response.StatusCode);
}
var json = await http_response.Content.ReadAsStringAsync().ConfigureAwait(false);
return parse(() => JsonSerializer.Deserialize<T>(json, JsonSerializerOptions.Default), json, extractor);
}
@@ -80,12 +88,16 @@ namespace BeWo.ServerUtils.ApiFacade
{
var http_response = await getResponseAsync(method).ConfigureAwait(false);
var content = await http_response.Content.ReadAsStringAsync().ConfigureAwait(false);
if (!http_response.IsSuccessStatusCode)
{
_logger.Error($"{http_response.ReasonPhrase} (Code:{http_response.StatusCode})");
_logger.Error(content);
return ApiResponse<T>.FailureResponse(AppError.ApiResponseFailed, http_response.ReasonPhrase, (int)http_response.StatusCode);
}
var content = await http_response.Content.ReadAsStringAsync().ConfigureAwait(false);
object result;
var type = typeof(T);

View File

@@ -40,6 +40,10 @@
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Lib\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=9.0.0.7, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Bcl.AsyncInterfaces.9.0.7\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>