Skip to content

.ReadFrom.Configuration(Configuration) does not load serilog.sinks.mssqlserver (dotnetcore 2.0) #111

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
sabbadino opened this issue Feb 27, 2018 · 5 comments · Fixed by #123

Comments

@sabbadino
Copy link

sabbadino commented Feb 27, 2018

serilog.sinks.mssqlserver\5.1.0
\serilog.settings.configuration\2.5.0
\serilog.aspnetcore\2.1.0
\serilog\2.6.0

public void Configure( ...
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration)
.CreateLogger();

appsettings

"Serilog": {
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "RollingFile",
"Args": { "pathFormat": "D:\IS2009\Service\MediaPortal.Events.Api\logs\mediaportal\events-{Date}.txt" }
},
{
"Name": "MSSqlServer",
"Args": {
"ConnectionString": "Data Source=...",
"TableName": "FullLog"
}
}
]
},

"RollingFile" is loaded but "MSSqlServer" is not , what am I doing wrong ?

}

if I do
var logger = new LoggerConfiguration()
.WriteTo.MSSqlServer(connectionString, tableName, columnOptions: columnOptions)
.CreateLogger();

It does work ?!

thank you
enrico

@tsimbalar
Copy link

Hi,

the name of the keys of the Args section in the json configuration file are the names of the parameters of the method ... but it is case-sensitive

In this case, the underlying method is :

public static LoggerConfiguration MSSqlServer(
            this LoggerSinkConfiguration loggerConfiguration,
            string connectionString,
            string tableName,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            int batchPostingLimit = MSSqlServerSink.DefaultBatchPostingLimit,
            TimeSpan? period = null,
            IFormatProvider formatProvider = null,
            bool autoCreateSqlTable = false,
            ColumnOptions columnOptions = null,
            string schemaName = "dbo"
)

so your config file should look like :

... stuff before ...
{
  "Name": "MSSqlServer",
  "Args": {
    "connectionString": "Data Source=...",
    "tableName": "FullLog"
 }
}
... stuff after ...

@sabbadino
Copy link
Author

Thank you, that was the problem ..
Wheere can I find a sample about settings columns options by json configuration ?
thank you
Enrico

@tsimbalar
Copy link

I believe it is not supported in json configuration at the moment ...

See #109 ; #74

@sabbadino
Copy link
Author

sabbadino commented Feb 28, 2018

thank you .

BTW : it seems I can redefine the name of basic "built in columns" :
var columnOptions = new ColumnOptions();
columnOptions.Id.ColumnName = "FullLogId";

but I find no way to change the data type
is it true ?

thank you
enrico

@MV10
Copy link
Contributor

MV10 commented May 9, 2018

BTW : it seems I can redefine the name of basic "built in columns" :
var columnOptions = new ColumnOptions();
columnOptions.Id.ColumnName = "FullLogId";
but I find no way to change the data type
is it true ?

Correct. PR123 will let you specify column options as long as you're using .NET Standard's Microsoft.Extensions.Configuration.

@MV10 MV10 closed this as completed in #123 Jul 9, 2018
MV10 added a commit that referenced this issue Jul 9, 2018
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

Successfully merging a pull request may close this issue.

3 participants