Skip to content

Configure columnOptionsSection in Json doesn't work #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Luxuride opened this issue Jul 17, 2018 · 35 comments
Closed

Configure columnOptionsSection in Json doesn't work #129

Luxuride opened this issue Jul 17, 2018 · 35 comments

Comments

@Luxuride
Copy link

Luxuride commented Jul 17, 2018

I have serilog config in Json. When I'm trying to add/remove columns, nothing happens.


Dependencies

Microsoft.AspNetCore.All (2.1.0)
Serilog.AspNetCore (2.1.1)
Serilog.Settings.Configuration (2.6.1)
Serilog.Sinks.MSSqlServer (5.1.2)

logsettings.json have Copy always (After config change Clean -> Rebuild)


Calling config

IConfiguration config = new ConfigurationBuilder()
        .AddJsonFile("logsettings.json", optional: true, reloadOnChange: true)
        .Build();

Log.Logger = new LoggerConfiguration()
         .ReadFrom.Configuration(config)
         .CreateLogger();

Config

{
    "Serilog": {
        "Using": [ "Serilog.Sinks.MSSqlServer" ],
        "MinimumLevel": {
            "Default": "Information",
            "Override": {
                "Microsoft": "Warning"
            }
        },
        "WriteTo": [
            {
                "Name": "MSSqlServer",
                "Args": {
                    "connectionString": "Server=localhost; Database=log; MultipleActiveResultSets=true; User ID=sa; Password=Admin1234",
                    "tableName": "Logs",
                    "autoCreateSqlTable": true,
                    "columnOptionsSection": {
                        "customColumns": [
                            {
                                "ColumnName": "Application",
                                "DataType": "string"
                            },
                            {
                                "ColumnName": "SourceContext",
                                "DataType": "string"
                            },
                            {
                                "ColumnName": "ActionId",
                                "DataType": "string"
                            },
                            {
                                "ColumnName": "ActionName",
                                "DataType": "string"
                            },
                            {
                                "ColumnName": "RequestId",
                                "DataType": "string"
                            },
                            {
                                "ColumnName": "RequestPath",
                                "DataType": "string"
                            },
                            {
                                "ColumnName": "ConnectionId",
                                "DataType": "string"
                            }
                        ], //Custom columns aren't in database
                        "addStandardColumns": [ "LogEvent" ], //LogEvent column still isn't in database
                        "removeStandardColumns": [ "MessageTemplate", "Properties" ], //Properties column is still in database
                        "logEvent": {
                            "columnName": "LogEvent",
                            "excludeAdditionalProperties": true
                        }
                    }
                }
            }
        ]
    }
}

Even config template did not work

{
"Serilog": {
    "Using":  ["Serilog.Sinks.MSSqlServer"],
    "MinimumLevel": "Debug",
    "WriteTo": [
    { "Name": "MSSqlServer", 
        "Args": { 
            "connectionString": "Server=localhost; Database=log; MultipleActiveResultSets=true; User ID=sa; Password=Admin1234",
            "tableName": "Logs",
            "autoCreateSqlTable": true,
            "columnOptionsSection": {
            "customColumns": [
                { "ColumnName": "EventType", "DataType": "int", "AllowNull": false },
                { "ColumnName": "Release", "DataType": "varchar", "DataLength": 32 }
            ]
            }
        } 
    }
    ]
}
}

In database are always these columns (None is added/removed)

| Id | Message | MessageTemplate | Level | TimeStamp | Exception | Properties |
@kalexx
Copy link

kalexx commented Aug 7, 2018

I am running in to the same problem.
I was wondering if there is a solution for this problem

@OculiViridi
Copy link

OculiViridi commented Aug 7, 2018

I've the same problem too. I'm also using the Serilog.Settings.Configuration 3.0.0-dev-00119, as suggested here, but the problem still remains.

It writes on Console and also creates the default table in SQL Server with the given name, but the columnOptionsSection configuration seems to be totally ignored. Options structure is taken from the GitHub repository of the project.
Instead, by setting the same configuration using the Fluent way, it works as expected.

UPDATE:

By adding the Serilog.Debugging.SelfLog.Enable(Console.Error); line to my application startup code, the following error appears on console:

2018-08-07T14:38:44.2797285Z Unable to write 4 log events to the database due to following error: The given ColumnMapping does not match up with any column in the source or destination.

This is my actual appsettings.json file:

{
  "ConnectionStrings": {
    "DbContext": "Server=..."
  },
  "Serilog": {
    "Enrich": "FromLogContext",
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "Microsoft": "Warning",
        "System": "Warning"
      }
    },
    "Using": [ "Serilog.Sinks.MSSqlServer" ],
    "WriteTo": [
      "Console",
      {
        "Name": "MSSqlServer",
        "Args": {
          "connectionString": "Server=...",
          "tableName": "Logs",
          "columnOptionsSection": {
            "addStandardColumns": [ "LogEvent" ],
            "removeStandardColumns": [ "Properties" ],
            "level": {
              "columnName": "Level",
              "storeAsEnum": true
            }
          },
          "autoCreateSqlTable": true
        }
      }
    ]
  }
}

UPDATE 2018/08/22:

I'm on .NET Core v2.1.

@MV10
Copy link
Contributor

MV10 commented Aug 7, 2018

@Luxuride the version you listed (5.1.2) doesn't have Microsoft.Extensions.Configuration support. That support was added last month (PR#123) and is currently only available in dev-release packages (at the moment, 5.1.3-dev00202).

@OculiViridi are you on the SQL release package or the dev package?

@OculiViridi
Copy link

OculiViridi commented Aug 8, 2018

@MV10 This is all my packages versions:

  • Serilog.AspNetCore v2.1.1
  • Serilog.Sinks.Console v3.1.1
  • Serilog.Sinks.MSSqlServer v5.1.2
  • Serilog.Settings.Configuration v3.0.0-dev-00119

I didn't know that even dev version of Serilog.Sinks.MSSqlServer was necessary. Anyway, what do you mean when you say

the version you listed (5.1.2) doesn't have Microsoft.Extensions.Configuration support

Because I have no problem with the code below:

Log.Logger = new LoggerConfiguration()
    .ReadFrom.Configuration(configuration)
    .CreateLogger();

UPDATE 2018/08/22:

I'm on .NET Core v2.1.

@kalexx
Copy link

kalexx commented Aug 8, 2018

@MV10 Thanks for the tip. I installed the version you mentioned but using dev-release packages (at the moment, 5.1.3-dev00202) throws the following exception:

Argument value should be of type Action<>.

at Serilog.Settings.Configuration.ConfigurationSectionArgumentValue.ConvertTo(Type toType, IReadOnlyDictionary 2 declaredLevelSwitches) at Serilog.Settings.Configuration.ConfigurationReader.<>c__DisplayClass17_3.<CallConfigurationMethods>b__4(<>f__AnonymousType6 2 <>h__TransparentIdentifier0) at System.Linq.Utilities.<>c__DisplayClass2_0 3.<CombineSelectors>b__0(TSource x) at System.Linq.Enumerable.SelectListPartitionIterator 2.ToList() at System.Linq.Enumerable.ToList[TSource](IEnumerable 1 source) at Serilog.Settings.Configuration.ConfigurationReader.CallConfigurationMethods(ILookup 2 methods, IList 1 configurationMethods, Object receiver, IReadOnlyDictionary 2 declaredLevelSwitches) at Serilog.Settings.Configuration.ConfigurationReader.Configure(LoggerConfiguration loggerConfiguration)
do you know if there is anything new in this Package?

@MV10
Copy link
Contributor

MV10 commented Aug 9, 2018

@OculiViridi Versions earlier than 5.1.3 were based upon the .NET Framework's XML-based ConfigurationManager (you can see this in the older readme which preceded my PR#123 in May that added .NET Standard multi-targeting and MS.Ext.Config v2 support).

@kalexx Since that's a new problem I'd suggest a new thread with some of your details -- which .NET you're targeting, your various packages, and your config.

@Luxuride
Copy link
Author

Luxuride commented Aug 10, 2018

@MV10 that error what happened to @kalexx is happening in the the program which is in this issue. All details are on this site.

Update:

Only difference is Serilog.Sinks.MSSqlServer(5.1.3-dev-00202)

@globtech1
Copy link

globtech1 commented Aug 16, 2018

Same configuration, the same problem. When switching to the dev package, get the same error: Argument value should be of type Action<>. Thanks

@paulpce
Copy link

paulpce commented Aug 22, 2018

Another user having the same issue with Serilog.Sinks.MSSqlServer(5.1.3-dev-00202) using .NET Core v2.1. Configuring in Startup using .WriteTo.MSSqlServer(...) works fine, but when using .ReadFrom.Configuration(Configuration) and the exact snippet from the README page, I get the same error Argument value should be of type Action<>:

{
  "Serilog": {
    "Using":  ["Serilog.Sinks.MSSqlServer"],
    "MinimumLevel": "Debug",
    "WriteTo": [
      { "Name": "MSSqlServer", 
        "Args": { 
            "connectionString": "Data Source=...",
            "tableName": "Logs",
            "columnOptionsSection": {
              "customColumns": [
                { "ColumnName": "EventType", "DataType": "int", "AllowNull": false },
                { "ColumnName": "Release", "DataType": "varchar", "DataLength": 32 }
              ]
            }
        } 
      }
    ]
  }
}

And I might add that the issue that led me here was the original one from the OP: I couldn't get custom columns written to using v5.1.2. The only way I've found that works is using v5.1.3-dev-00202 and .WriteTo.MSSqlServer(...)

@MV10
Copy link
Contributor

MV10 commented Aug 22, 2018

Everyone, please update with the .NET you're targeting -- Framework or Core?

@kalexx
Copy link

kalexx commented Aug 22, 2018

@MV10 I am using .NET Core 2.1

@OculiViridi
Copy link

@MV10 Updated my posts. I'm on .NET Core v2.1.

@paulpce
Copy link

paulpce commented Aug 22, 2018

@MV10 Also .NET Core v2.1

@MV10
Copy link
Contributor

MV10 commented Aug 22, 2018

Thanks everyone. I'll try to reproduce this today.

@MV10
Copy link
Contributor

MV10 commented Aug 22, 2018

Quick update, a basic .NET Core 2.1 console app is able to use the README configuration to create the database and write log entries correctly. Next I'll set up a simple ASP.NET Core test.

These are the packages I'm using, I think they're equivalent to what everyone has reported above. (The last two are local builds from source pulled from the current dev branches today).

  • Microsoft.Extensions.Configuration v2.1.1
  • Microsoft.Extensions.Configuration.FileExtensions v2.1.1
  • Microsoft.Extensions.Configuration.Json v2.1.1
  • Serilog v2.6.0
  • Serilog.Sinks.Console v3.1.1
  • Serilog.Settings.Configuration v3.0.0-m0001
  • Serilog.Sinks.MSSqlServer v5.1.3-m0001

Configuration -- exactly as shown in the README (copied from the post by @paulpce above, actually) except I added Console output, and to demonstrate these other features work, autoCreateSqlTable and removeStandardColumns:

{
  "Serilog": {
    "Using":  ["Serilog.Sinks.MSSqlServer"],
    "MinimumLevel": "Debug",
    "WriteTo": [
      "Console",
      { "Name": "MSSqlServer", 
        "Args": { 
          "connectionString": "Data Source=(LocalDB)\\MSSQLLocalDB;Initial Catalog=SerilogTest;Integrated Security=True;",
            "tableName": "Logs",
          "autoCreateSqlTable": true,
            "columnOptionsSection": {
            "removeStandardColumns": [ "Properties" ],
              "customColumns": [
                { "ColumnName": "EventType", "DataType": "int", "AllowNull": false },
                { "ColumnName": "Release", "DataType": "varchar", "DataLength": 32 }
              ]
            }
        } 
      }
    ]
  }
}  

Console program:

var appConfig = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
    .Build();

var logConfig = new LoggerConfiguration();
logConfig.ReadFrom.Configuration(appConfig);
var logger = logConfig.CreateLogger();

logger.Information("Release is nullable {EventType} {Release}", 123, "1.0.0");
logger.Information("An Information message {EventType}", 100);
logger.Warning("A Warning message {EventType}", 200);
logger.Error("An Error message {EventType}", 300);
logger.Verbose("A Verbose message {EventType}", 400);
logger.Debug("A Debug message {EventType}", 500);

logger.Dispose();

The database it generated (the custom fields are added and the Properties field is removed):

image

Rows written to the database:

image

@MV10
Copy link
Contributor

MV10 commented Aug 22, 2018

Also reproduced the results above using the NuGet dev packages. (Figured it can't hurt to double-check.)

@MV10
Copy link
Contributor

MV10 commented Aug 22, 2018

For ASP.NET Core, I suspect there is a problem with Serilog itself. Without using configuration or SQL, just logging to the console, configured in code, I get zero log output on a new template project.

My test uses the following:

  • Microsoft.AspNetCore.App v2.1.1
  • Microsoft.NetCore.App v2.1.0
  • Serilog v2.6.0 (same result with v2.7.1)
  • Serilog.AspNetCore v2.1.1
  • Serilog.Settings.Configuration v3.0.0-dev-00119
  • Serilog.Sinks.Console v3.1.1
  • Serilog.Sinks.MSSqlServer v5.1.3-dev-00202

Configuration seems to work, SQL Server creates the table if it is missing and the correct options are applied. After calling CreateLogger I can inspect the returned Logger object and see the console and SQL sinks, but the output goes nowhere. SelfLog does not throw exceptions. Log events added to the index page OnGet are also not logged.

This time I used a less complicated configuration:

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.MSSqlServer" ],
    "MinimumLevel": "Debug",
    "WriteTo": [
      "Console",
      {
        "Name": "MSSqlServer",
        "Args": {
          "connectionString": "Data Source=(LocalDB)\\MSSQLLocalDB;Initial Catalog=SerilogTest;Integrated Security=True;",
          "tableName": "Logs",
          "autoCreateSqlTable": true,
          "columnOptionsSection": {
            "addStandardColumns": [ "LogEvent" ],
            "removeStandardColumns": [ "Properties" ]
          }
        }
      }
    ]
  },
  "AllowedHosts": "*"
}

There is nothing unusual about my web host runner:

public static void Main(string[] args)
{
    var appConfig = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
        .Build();

    var logConfig = new LoggerConfiguration()
        .ReadFrom.Configuration(appConfig)
        .CreateLogger();

    Serilog.Debugging.SelfLog.Enable(Console.Error);

    try
    {
        Log.Information("Starting web host");
        CreateWebHostBuilder(args).Build().Run();
    }
    catch (Exception ex)
    {
        Log.Fatal(ex, "Web host failed");
    }
    finally
    {
        Log.CloseAndFlush();
    }
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .UseSerilog();

I also tried eliminating SQL and configuration completely (I even removed the packages) and switched to configuration through code. This also does not produce any console logging at all:

var logConfig = new LoggerConfiguration()
    //.ReadFrom.Configuration(appConfig)
    .MinimumLevel.Debug()
    .WriteTo.Console()
    .CreateLogger();

So I haven't been able to reproduce any of the problems in this thread, but it sure looks like something is wrong in Serilog itself. I will continue digging, it's probably some version mismatch, Microsoft put out a lot of point releases, and most of these other packages have dev or pre-release versions, too.

If somebody can create a repository with a simple ASP.NET Core app that throws the configuration error, I'd like to take a look at that (e.g. start a new, blank app, and reproduce it there).

@MV10
Copy link
Contributor

MV10 commented Aug 22, 2018

By the way, just blindly copying the README config into an existing app will not be useful because the sample EventType column has allowNull : false -- so no rows will be written unless you add {EventType} to all of your log output. 👍

@MV10
Copy link
Contributor

MV10 commented Aug 22, 2018

Ok, after fixing my embarassing cut-and-paste error, I am getting full, normal logging out of ASP.NET Core. I'm going to need someone to set up a simple reproduction app to troubleshoot any further.

image

The logger setup should have been as follows, and then everything else works normally:

    // WRONG... var logConfig = new LoggerConfiguration()
    Log.Logger = new LoggerConfiguration()
        .ReadFrom.Configuration(appConfig)
        .CreateLogger();

@paulpce
Copy link

paulpce commented Aug 23, 2018

Thanks @MV10, I've just reproduced it in a clean ASP.Net Core Web app project. Versions:

  • Microsoft.NETCore.App v2.1.0
  • Microsoft.AspNetCore.App v2.1.1
  • Serilog.AspNetCore v2.1.1
  • Serilog.Settings.Configuration v2.6.1
  • Serilog.Sinks.MSSqlServer v5.1.3-dev-00202

(no other Nuget packages installed)

Startup.cs:

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
        Log.Logger = new LoggerConfiguration()
            .ReadFrom.Configuration(Configuration)
            .CreateLogger();
    }
    // ...

appSettings.json:

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*",
  "Serilog": {
    "Using": [ "Serilog.Sinks.MSSqlServer" ],
    "WriteTo": [
      {
        "Name": "MSSqlServer",
        "Args": {
          "connectionString": "Data Source=...",
          "tableName": "Log",
          "columnOptionsSection": {
            "removeStandardColumns": [ "MessageTemplate", "Properties", "LogEvent" ],
            "customColumns": [
              {
                "ColumnName": "ConnectionId",
                "DataType": "varchar",
                "DataLength": 30
              }
            ]
          }
        }
      }
    ],
    "MinimumLevel": "Debug",
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
  }
}

I've noticed that removing customColumns entirely from the appSettings config stops the error from happening (but leaving customColumns in with an empty set still causes the error to occur).

I've left out the other methods in Startup.cs as they don't even get executed, the exception happens on .ReadFrom.Configuration(Configuration). If you can't reproduce with that information above let me know and I'll post my entire project somewhere online.

@MV10
Copy link
Contributor

MV10 commented Aug 23, 2018

@paulpce As noted in the SQL sink README, you should be using a 3.0.0-dev or newer package for Serilog.Settings.Configuration. Please bump it up and let me know if things improve.

I tried a blank customColumns and a blank columnOptionsSection and both appear to work, but I do see the column mapping SelfLog messages in the console that I want to investigate. The really weird part is that it does still create the table and write log entries into it.

Edit: SelfLog messages were correct, I blanked those parts of the config but I was still using a table from an autocreate config where I'd removed the Properties column, so my config no longer matched the real schema.

So I'm back to not seeing any issues under ASP.NET Core.

@paulpce
Copy link

paulpce commented Aug 23, 2018

@MV10 You were totally right about the Serilog.Settings.Configuration package. Updating that to the latest pre-release fixed it. My apologies, I totally missed that bit. Thanks for your help - looking forward to the next release.

@MV10
Copy link
Contributor

MV10 commented Aug 23, 2018

@paulpce No problem, glad you're back in business. I didn't expect the config package to sit in dev for so long (still relatively new to the contribution side of this ecosystem), it probably needs to be highlighted better in the readme.

Is there anybody else left with issues? I'll leave this open for a few days but I suspect this was all about package versions.

@OculiViridi
Copy link

OculiViridi commented Aug 24, 2018

@MV10 Please refer to serilog/serilog-settings-configuration#126 (comment) for JSON configuration error that still remains...

@MV10
Copy link
Contributor

MV10 commented Aug 24, 2018

@OculiViridi yeah I saw that one, it's almost certainly in the SQL sink, but since you had other config issue/questions, we'll work through that one over there.

@OculiViridi
Copy link

@MV10 Ok! Thanks!

@MV10
Copy link
Contributor

MV10 commented Aug 27, 2018

If anyone still has issues, let me know and we can re-open this.

@EEParker
Copy link

EEParker commented Sep 19, 2018

@MV10 I have a corner case where I have a project using aspnetcore 2.1.3, but the target framework is .net 4.7.2 due to some legacy components.

In this case, the appsettings.json column options are not applied. Since nuget defaults to use the net45 version, the compile options here change the functionality:
https://github.com/serilog/serilog-sinks-mssqlserver/blob/dev/src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj#L54
and
https://github.com/serilog/serilog-sinks-mssqlserver/blob/dev/src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj#L44

Currenly I am including this code as a submodule, and only compiling targeting this library as netstandard2.0 which seems to work. Do know of any way around this?

@MV10
Copy link
Contributor

MV10 commented Sep 20, 2018

@EEParker off-hand, no, I don't know how to address that, but I will research it and let you know if I find anything. I actually thought that question would arise sooner!

@danushkap
Copy link

danushkap commented May 20, 2019

If anyone still has issues, let me know and we can re-open this.

@MV10, yes, my columnOptionsSection is not working.

I am using .NET Core 2.1

And these are the packages (full-list) I'm using:

Microsoft.Extensions.Configuration.CommandLine "2.2.0"
Microsoft.Extensions.Configuration.EnvironmentVariables "2.2.4"
Microsoft.Extensions.Configuration.FileExtensions "2.2.0"
Microsoft.Extensions.Configuration.Json "2.2.0"
Microsoft.Extensions.Hosting "2.2.0"
Serilog "2.8.0"
Serilog.AspNetCore "2.1.1"
Serilog.Settings.Configuration "3.0.1"
Serilog.Sinks.ColoredConsole "3.0.1"
Serilog.Sinks.MSSqlServer "5.1.2"
Serilog.Sinks.RollingFile "3.3.0"

Config:

"columnOptionsSection": { "removeStandardColumns": [ "Properties" ] }

But I still get the Properties field in the DB

Update: I updated Serilog.Settings.Configuration to 3.0.2-dev-00195 yet, the Properties is coming up

(please let me know if you need more info) thanks!

@OculiViridi
Copy link

OculiViridi commented May 21, 2019

@MV10

If anyone still has issues, let me know and we can re-open this.

Now I've only a problem with the automatic creation of database.

"autoCreateSqlTable": true

By enabling Serilog selflog

Serilog.Debugging.SelfLog.Enable(Console.Error);

I see this exception:

2019-05-21T08:01:38.2723271Z Exception creating table Logs:
System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) ---> System.ComponentModel.Win32Exception (233): No process is on the other end of the pipe
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Serilog.Sinks.MSSqlServer.SqlTableCreator.CreateTable()
at Serilog.Sinks.MSSqlServer.MSSqlServerSinkTraits..ctor(String connectionString, String tableName, String schemaName, ColumnOptions columnOptions, IFormatProvider formatProvider, Boolean autoCreateSqlTable)
ClientConnectionId:9db25366-ec1b-4183-ba56-1ceb67cb3448
Error Number:233,State:0,Class:20

The SQL Server dcslog user has the db_createdatabase role and by SMSS I can succesfully login to the DB and create a new database.

I'm currently using:

  • ASP.NET Core v2.1.603
  • Serilog.AspNetCore v2.1.1
  • Serilog.Settings.Configuration v3.0.1
  • Serilog.Sinks.MSSqlServer v5.1.3-dev-00236

@OculiViridi
Copy link

Any news about this?

Also, when will it be available the final release of this 5.1.3 version?

@Jaroszt
Copy link

Jaroszt commented Aug 22, 2019

I am getting this issue. I am using a dedicated external json file for the configuration.

Packages:
Microsoft.Configuration.Json 2.2.0
Serilog 2.8
Serilog.Settings.Configuration 3.1
Serilog.Sinks.Console 3.1.1
Serilog.Sinks.MSSqlServer 5.1.2

Startup:

var config = new ConfigurationBuilder().AddJsonFile("somelocation").Build();
var logger = new LoggerConfiguration().ReadFrom.Configuration(config).CreateLogger();
logger.Error("Hello World");

Config File:
{
"Serilog": {
"Using": ["Serilog.Sinks.Console", "Serilog.Sinks.MSSqlServer"],
"MinimumLevel": "Debug",
"WriteTo": [
{"Name": "Console"},
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "someconnection",
"tableName": "Log2",
"restrictedToMinimumLevel": "Information",
"autoCreateSqlTable": true,
"columnOptionsSection": {
"removeStandardColumns": [ "Properties" ],
"customColumns": [
{ "ColumnName": "EventType", "DataType": "int", "AllowNull": false },
{ "ColumnName": "Release", "DataType": "varchar", "DataLength": 32 }
]
}

	}
  }
]

}
}

@vietlp
Copy link

vietlp commented Aug 26, 2019

The issue happens again, the 'columnOptionsSection' doesn't work. I'm using 'Serilog.Extensions.Logging' v3.0.1 and 'Serilog.Sinks.MSSqlServer' v5.1.2

[UPDATE]
I'm using .NET Core 2.2.6

@pcuycs
Copy link

pcuycs commented Sep 23, 2019

I am used
.net core 2.2
Serilog.AspNetCore: 3.0.0
Serilog.Sinks.MSSqlServer: 5.1.2
Serilog.Extensions.Logging: 3.0.1

CREATE TABLE [dbo].[LogsTest](
[ID] [INT] IDENTITY(1,1) NOT NULL,
[Message] NVARCHAR NULL,
[MessageTemplate] NVARCHAR NULL,
[Level] NVARCHAR NULL,
[TimeStamp] [DATETIME] NOT NULL,
[Exception] NVARCHAR NULL,
[Properties] NVARCHAR NULL,
CONSTRAINT [PK_dbo.LogsTest] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

{
"Serilog": {
"Using": [ "Serilog.Sinks.MSSqlServer" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "Data Source=.\SQLEXPRESS; Initial Catalog=Test;Integrated Security=True;MultipleActiveResultSets=True;", // connection String
"tableName": "LogsTest", // table name Logs is okay
"autoCreateSqlTable": false// true is okay
},
}
]
},
"AllowedHosts": "*"
}

I can't write log to MSSQL when i using serilog with the table name different the default value. If i set default value, it is okay.
Anyone can help me? thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests