标签: ms-yarp

如何在 ASP.NET Core Web 应用程序中登录到文件 - 无需任何第三方工具

我目前正在运行一个应用程序,我希望将日志放入文件中,以便 Datadog 能够获取它们。

我目前只使用源生成器来记录,但如何将这些日志记录到文件中?

我尝试更改 web.config 并将其部署到 iis,但似乎没有任何内容记录到文件中,然后我手动创建了日志文件夹,但似乎仍然没有放入任何内容。

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <!-- To customize the asp.net core module uncomment and edit the following section. 
  For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
    
  <system.webServer>
    <handlers>
      <remove name="aspNetCore"/>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
  </system.webServer>


</configuration>
Run Code Online (Sandbox Code Playgroud)

那么我如何将日志保存到文件中呢?

我目前如何登录

public partial class RequestResponseLoggerMiddleware
{
    private readonly RequestDelegate _next;
    private readonly ILogger _logger;

    public RequestResponseLoggerMiddleware(RequestDelegate next,
                                    ILoggerFactory loggerFactory)
    {
        _next = next;
        _logger = loggerFactory
                  .CreateLogger<RequestResponseLoggerMiddleware>();
    }

    [LoggerMessage(0, …
Run Code Online (Sandbox Code Playgroud)

c# logging datadog asp.net-core ms-yarp

6
推荐指数
1
解决办法
7276
查看次数

Microsoft C# .NET YARP 504 网关错误和故障转移

我使用 Microsoft C# .NET YARP作为 ASP.NET Core Web API(最新版本)以及 Swagger 和 Kestrel 前面的 API 网关。YARP 用于到许多微服务的内部重定向。

问题:

  1. 对于执行超过大约 504 的请求,我面临 504 http API 网关错误。距 swagger UI 2 分钟。如何设置更长的超时时间?

例如:https://URL/swagger/index.html => 执行 POST FUNCTION => YARP_API_GATEWAY => SERVICE_API_PORT

  1. 如果内部服务目标(端点)因任何原因关闭,如何将“故障转移”配置到另一个目标?

前任。配置:

   "ReverseProxy": {
    "Routes": [
      {
        "RouteId": "Service1",
        "ClusterId": "ServiceCluster1",
        "Match": {
          "Path": "/api/Action1/{**rest}"
        },
        "Transforms": [
          { "RequestHeadersCopy": "true" },
          { "RequestHeaderOriginalHost": "true" }
        ]
      },
      {
        "RouteId": "Service2",
        "ClusterId": "ServiceCluster2",
        "Match": {
          "Path": "/api/Action2/{**rest}"
        },
        "Transforms": [
          { "RequestHeadersCopy": …
Run Code Online (Sandbox Code Playgroud)

c# failover api-gateway ms-yarp

5
推荐指数
1
解决办法
2457
查看次数

标签 统计

c# ×2

ms-yarp ×2

api-gateway ×1

asp.net-core ×1

datadog ×1

failover ×1

logging ×1