Неверный URI: невозможно определить формат URI в ядре asp.net - PullRequest
0 голосов
/ 09 ноября 2018

Я использую serilog и Seq в своей основной программе Asp.net, но продолжаю получать вышеуказанную ошибку. Мой сервер Seq работает, хотя. Найдите ниже конфигурации в appsetting.json и startup.cs соответственно.

Appsetting.json

"Serilog": {
    "Destructure": [
      {
        "Name": "With",
        "Args": { "policy": "Sample.CustomPolicy, Sample" }
      },
      {
        "Name": "ToMaximumDepth",
        "Args": { "maximumDestructuringDepth": 4 }
      },
      {
        "Name": "ToMaximumStringLength",
        "Args": { "maximumStringLength": 100 }
      },
      {
        "Name": "ToMaximumCollectionCount",
        "Args": { "maximumCollectionCount": 10 }
      }
    ],
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
    "MinimumLevel": "Debug",
    "Properties": {
      "Application": "Sample"
    },
    "Using": [ "Serilog.Sinks.File", "Serilog.Sinks.Async", "Serilog.Sinks.Console", "Serilog.Sinks.Seq", "Serilog.Sinks.Graylog" ],
    "WriteTo": [
      {
        "Name": "Console"

      },
      {
        "Name": "File",
        "Args": { "path": "Loggers/logs.txt" }
      },
      {
        "Args": {
          "serverUrl": "http://localhost:5341"

        },
        "Name": "Seq"
      }
    ]
  }

StartUp.cs

 services.AddLogging(loggingBuilder =>
 {
     loggingBuilder.AddSeq("Seq");
 });

1 Ответ

0 голосов
/ 12 ноября 2018

Для loggingBuilder.AddSeq("Seq"); вам нужно передать URL вместо Seq.

    //
// Summary:
//     Extends Microsoft.Extensions.Logging.ILoggerFactory with methods for configuring
//     Seq logging.
public static class SeqLoggerExtensions
{
    //
    // Summary:
    //     Adds a Seq logger configured from the supplied configuration section.
    //
    // Parameters:
    //   loggerFactory:
    //     The logger factory.
    //
    //   configuration:
    //     A configuration section with details of the Seq server connection.
    //
    // Returns:
    //     A logger factory to allow further configuration.
    public static ILoggerFactory AddSeq(this ILoggerFactory loggerFactory, IConfigurationSection configuration);
    //
    // Summary:
    //     Adds a Seq logger.
    //
    // Parameters:
    //   loggerFactory:
    //     The logger factory.
    //
    //   serverUrl:
    //     The Seq server URL; the default is http://localhost:5341.
    //
    //   apiKey:
    //     A Seq API key to authenticate or tag messages from the logger.
    //
    //   minimumLevel:
    //     The level below which events will be suppressed (the default is Microsoft.Extensions.Logging.LogLevel.Information).
    //
    //   levelOverrides:
    //     A dictionary mapping logger name prefixes to minimum logging levels.
    //
    // Returns:
    //     A logger factory to allow further configuration.
    public static ILoggerFactory AddSeq(this ILoggerFactory loggerFactory, string serverUrl = "http://localhost:5341", string apiKey = null, LogLevel minimumLevel = LogLevel.Information, IDictionary<string, LogLevel> levelOverrides = null);
    //
    // Summary:
    //     Adds a Seq logger.
    //
    // Parameters:
    //   loggingBuilder:
    //     The logging builder.
    //
    //   serverUrl:
    //     The Seq server URL; the default is http://localhost:5341.
    //
    //   apiKey:
    //     A Seq API key to authenticate or tag messages from the logger.
    //
    // Returns:
    //     A logging builder to allow further configuration.
    public static ILoggingBuilder AddSeq(this ILoggingBuilder loggingBuilder, string serverUrl = "http://localhost:5341", string apiKey = null);
    //
    // Summary:
    //     Adds a Seq logger configured from the supplied configuration section.
    //
    // Parameters:
    //   loggingBuilder:
    //     The logging builder.
    //
    //   configuration:
    //     A configuration section with details of the Seq server connection.
    //
    // Returns:
    //     A logging builder to allow further configuration.
    public static ILoggingBuilder AddSeq(this ILoggingBuilder loggingBuilder, IConfigurationSection configuration);
}

Если вы хотите передать конфигурацию из appsettings.json, определите appsettings.json как

    "Seq": {
  "ServerUrl": "http://localhost:5341",
  "ApiKey": "1234567890",
  "MinimumLevel": "Trace",
  "LevelOverride": {
    "Microsoft": "Warning"
  }
}

И используя как loggingBuilder.AddSeq(Configuration.GetSection("Seq"));.

Если вам нужно объединить serilog и Seq, см. Использование Serilog .

Log.Logger = new LoggerConfiguration()
        .WriteTo.Console()
        .WriteTo.Seq("http://localhost:5341")
        .CreateLogger();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...