Serilog MSSqlServer 接收器是否应该与 Azure SQL 服务器一起使用?

Is Serilog MSSqlServer sink supposed to work with Azure SQL Server?

我有一个 ASP.Net Core 2.1 web API 可以毫无问题地连接到 Azure SQL 服务器作为后备数据存储。

我目前正在尝试设置 Serilog,以便它将错误写入我的 Azure SQL 服务器数据库中的 "ApiLog" table。我正在使用 MSSqlServer sink for Serilog and following the setup described in this blog。我在 Program.cs 中使用以下代码来查看任何 Serilog 错误;

        Serilog.Debugging.SelfLog.Enable(msg =>A
        {
            Debug.Print(msg);
            Debugger.Break();
        });

...我收到此错误;

Unable to write 1 log events to the database due to following error: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host

我在 API 的数据库上下文 [=44] 中连接到 Azure SQL 服务器(相同的服务器和数据库,但不同的数据库 tables)没有任何问题=] 所以我不确定是什么问题。我为我的数据库上下文连接使用与用于 Serilog 相同的 SQL 登录帐户。

这是我在 appsettings.json;

中的 writeto 部分
"WriteTo": [
  {
    "Name": "MSSqlServer",
    "Args": {
      "connectionString": "Server=<server name in Azure>.database.windows.net,1433;Initial Catalog=Logs;Persist Security Info=False;User ID=<SQL account name>;Password=<Sql Account Password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
      "tableName": "ApiLog"
    }
  },

我什至尝试将用户 ID 和用户密码设置为 SA 登录作为测试,但出现了同样的错误,所以我认为这不是权限问题 SQL 服务器问题。

所以,我想知道...Azure SQL 服务器是否真的支持 Serilog MSSqlServer 接收器?到目前为止,我还没有在互联网上找到任何具体的说法。

有什么想法吗?

我只是使用文档作为指南在本地控制台应用程序中进行了尝试,它运行良好。

// This doesn't break/I don't get any exceptions.
Serilog.Debugging.SelfLog.Enable(msg =>
{
    Debug.Print(msg);
    Debugger.Break();
});

var tableName = "Logs";
var connectionString = "Server=SERVER;Database=DATABASE;User Id=USERNAME;Password=PASSWORD;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Persist Security Info=False;";

var log = new LoggerConfiguration()
    .WriteTo.MSSqlServer(connectionString, tableName)
    .CreateLogger();

log.Write(Serilog.Events.LogEventLevel.Error, "It works");

没有连接错误。

文档示例:https://github.com/serilog/serilog-sinks-mssqlserver#code-net-framework

我自己制作了 table,我没有尝试自动创建:https://github.com/serilog/serilog-sinks-mssqlserver#table-definition

这是 table 中的行:

Id 消息 MessageTemplate 级别时间戳异常属性

1 有效 有效 错误 2018-09-28 17:11:04.1189594 +01:00 NULL