Ошибка подключения Serilog MSSqlServer HTTPs

#asp.net-core #https #serilog

#asp.net-core #https #serilog

Вопрос:

При использовании .net core 3.1 и serilog sql server sink данные не будут записаны в базу данных. Включение самоблогирования serilog вот следующая ошибка на моей консоли:

Не удалось аутентифицировать HTTPS-соединение. System.IO.IOException: сбой аутентификации, поскольку удаленная сторона закрыла транспортный поток.

После создания базы данных вручную и запуска приложения таблица «ErrorLog» создается внутри базы данных (с использованием конфигурации serilog), но когда дело доходит до вставки журналов, это происходит.

Обновить

Независимо от того, какой приемник я использую, я сталкиваюсь с той же ошибкой!

 [17:14:10 INF] Hello, world!
[17:14:10 DBG] Hosting starting
[17:14:10 DBG] Failed to locate the development https certificate at 'null'.
[17:14:10 DBG] Using development certificate: CN=localhost (Thumbprint: 042981E3AFFFDD00DE844A41D4437C2A52529AEB)
[17:14:10 INF] Now listening on: https://localhost:5001
[17:14:10 INF] Now listening on: http://localhost:5000
[17:14:10 DBG] Loaded hosting startup assembly demo-log
[17:14:10 INF] Application started. Press Ctrl C to shut down.
[17:14:10 INF] Hosting environment: Development
[17:14:10 INF] Content root path: C:UsersOmidsourcereposdemo-logdemo-log
[17:14:10 DBG] Hosting started
[17:14:11 DBG] Connection id "0HM29NMTJB5T6" received FIN.
[17:14:11 DBG] Connection id "0HM29NMTJB5T7" received FIN.
[17:14:11 DBG] Connection id "0HM29NMTJB5T7" accepted.
[17:14:11 DBG] Connection id "0HM29NMTJB5T6" accepted.
[17:14:11 DBG] Connection id "0HM29NMTJB5T7" started.
[17:14:11 DBG] Connection id "0HM29NMTJB5T6" started.
[17:14:11 DBG] Failed to authenticate HTTPS connection.
System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
   at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.ProcessAuthentication(LazyAsyncResult lazyResult, CancellationToken cancellationToken)
   at System.Net.Security.SslStream.BeginAuthenticateAsServer(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken, AsyncCallback asyncCallback, Object asyncState)
   at System.Net.Security.SslStream.<>c.<AuthenticateAsServerAsync>b__69_0(SslServerAuthenticationOptions arg1, CancellationToken arg2, AsyncCallback callback, Object state)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl[TArg1,TArg2](Func`5 beginMethod, Func`2 endFunction, Action`1 endAction, TArg1 arg1, TArg2 arg2, Object state, TaskCreationOptions creationOptions)
   at System.Threading.Tasks.TaskFactory.FromAsync[TArg1,TArg2](Func`5 beginMethod, Action`1 endMethod, TArg1 arg1, TArg2 arg2, Object state, TaskCreationOptions creationOptions)
   at System.Threading.Tasks.TaskFactory.FromAsync[TArg1,TArg2](Func`5 beginMethod, Action`1 endMethod, TArg1 arg1, TArg2 arg2, Object state)
   at System.Net.Security.SslStream.AuthenticateAsServerAsync(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware.InnerOnConnectionAsync(ConnectionContext context)
[17:14:11 DBG] Failed to authenticate HTTPS connection.
System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
   at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.ProcessAuthentication(LazyAsyncResult lazyResult, CancellationToken cancellationToken)
   at System.Net.Security.SslStream.BeginAuthenticateAsServer(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken, AsyncCallback asyncCallback, Object asyncState)
   at System.Net.Security.SslStream.<>c.<AuthenticateAsServerAsync>b__69_0(SslServerAuthenticationOptions arg1, CancellationToken arg2, AsyncCallback callback, Object state)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl[TArg1,TArg2](Func`5 beginMethod, Func`2 endFunction, Action`1 endAction, TArg1 arg1, TArg2 arg2, Object state, TaskCreationOptions creationOptions)
   at System.Threading.Tasks.TaskFactory.FromAsync[TArg1,TArg2](Func`5 beginMethod, Action`1 endMethod, TArg1 arg1, TArg2 arg2, Object state, TaskCreationOptions creationOptions)
   at System.Threading.Tasks.TaskFactory.FromAsync[TArg1,TArg2](Func`5 beginMethod, Action`1 endMethod, TArg1 arg1, TArg2 arg2, Object state)
   at System.Net.Security.SslStream.AuthenticateAsServerAsync(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware.InnerOnConnectionAsync(ConnectionContext context)
[17:14:11 DBG] Connection id "0HM29NMTJB5T7" stopped.
[17:14:11 DBG] Connection id "0HM29NMTJB5T6" stopped.
[17:14:11 DBG] Connection id "0HM29NMTJB5T6" sending FIN because: "The Socket transport's send loop completed gracefully."
[17:14:11 DBG] Connection id "0HM29NMTJB5T7" sending FIN because: "The Socket transport's send loop completed gracefully."
[17:14:11 DBG] Connection id "0HM29NMTJB5T8" accepted.
[17:14:11 DBG] Connection id "0HM29NMTJB5T8" started.
[17:14:11 VRB] Connection id "0HM29NMTJB5T8" sending SETTINGS frame for stream ID 0 with length 18 and flags NONE
[17:14:11 VRB] Connection id "0HM29NMTJB5T8" sending WINDOW_UPDATE frame for stream ID 0 with length 4 and flags 0x0
[17:14:11 VRB] Connection id "0HM29NMTJB5T8" received SETTINGS frame for stream ID 0 with length 24 and flags NONE
[17:14:11 VRB] Connection id "0HM29NMTJB5T8" sending SETTINGS frame for stream ID 0 with length 0 and flags ACK
[17:14:11 VRB] Connection id "0HM29NMTJB5T8" received WINDOW_UPDATE frame for stream ID 0 with length 4 and flags 0x0
[17:14:11 VRB] Connection id "0HM29NMTJB5T8" received HEADERS frame for stream ID 1 with length 341 and flags END_STREAM, END_HEADERS, PRIORITY
[17:14:11 VRB] Connection id "0HM29NMTJB5T8" received SETTINGS frame for stream ID 0 with length 0 and flags ACK
[17:14:11 INF] Request starting HTTP/2 GET https://localhost:5001/
[17:14:11 DBG] Wildcard detected, all requests with hosts will be allowed.
[17:14:11 VRB] All hosts are allowed.
[17:14:11 DBG] No candidates found for the request path '/'
[17:14:11 DBG] Request did not match any endpoints
[17:14:11 INF] HTTP GET / responded 404 in 16.8270 ms
[17:14:11 VRB] Connection id "0HM29NMTJB5T8" sending HEADERS frame for stream ID 1 with length 71 and flags END_STREAM, END_HEADERS
  

Ответ №1:

Использовать Serilog для входа в базу данных MSSQL. Пожалуйста, используйте следующие шаги.

  1. Установите указанные ниже необходимые пакеты.
    Serilog
    Serilog.Падает.MSSQL
    Serilog.Падает.Периодический сбор
  2. Создайте файл класса и напишите свою функцию для входа в базу данных со ссылкой на приведенные ниже шаги.
     using Serilog;
    using Serilog.Sinks.MSSqlServer;
    using System.Diagnostics;
    try
        {
           // This doesn't break/I don't get any exceptions.
          Serilog.Debugging.SelfLog.Enable(msg =>
          {
            Debug.Print(msg);
            Debugger.Break();
          });
            var serLog = new LoggerConfiguration()
                           .WriteTo.MSSqlServer("yourconnectionstring", 
                             "yourtablename")
                            .CreateLogger();
    
            Log.Logger = serLog;
    
            Log.Information("It works");
        }
        catch (Exception ex)
        {
            Log.Error(ex.ToString());
        }
        finally
        {
            Log.CloseAndFlush();
        }