Skip to content

Configure columnOptionsSection in Json doesn't work #129

@Luxuride

Description

@Luxuride

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 |

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions