You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

43 lines
1.1 KiB

using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
namespace MyAvaloniaApp.Services;
/// <summary>
/// API 服务实现
/// </summary>
public class ApiService : IApiService
{
private readonly ILogger<ApiService>? _logger;
public ApiService(ILogger<ApiService>? logger = null)
{
_logger = logger;
_logger?.LogInformation("ApiService 已创建");
}
public async Task<string> GetApiDataAsync(string endpoint)
{
_logger?.LogInformation("调用 API: {Endpoint}", endpoint);
// 模拟 API 调用
await Task.Delay(500);
var result = $"API 响应数据来自 {endpoint} - {DateTime.Now:HH:mm:ss}";
_logger?.LogDebug("API 响应: {Result}", result);
return result;
}
public async Task<bool> PostDataAsync(string endpoint, object data)
{
_logger?.LogInformation("POST 数据到 API: {Endpoint}", endpoint);
// 模拟 API 调用
await Task.Delay(300);
_logger?.LogDebug("数据已发送: {Data}", data);
return true;
}
}