Skip to content
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

System.MissingMethodException: Method not found: 'Serilog.LoggerConfiguration Serilog.LoggerConfigurationMSSqlServerExtensions.MSSqlServer #290

Closed
saisworld opened this issue May 26, 2020 · 9 comments
Assignees
Labels

Comments

@saisworld
Copy link

Bug Report

Latest version of nuget sink.MSSQLServer 5.4.0 is throwing the below error -

System.MissingMethodException: 'Method not found: 'Serilog.LoggerConfiguration Serilog.LoggerConfigurationMSSqlServerExtensions.MSSqlServer(Serilog.Configuration.LoggerSinkConfiguration, System.String, Serilog.Sinks.MSSqlServer.Sinks.MSSqlServer.Options.SinkOptions, Microsoft.Extensions.Configuration.IConfiguration, Serilog.Events.LogEventLevel, System.IFormatProvider, Serilog.Sinks.MSSqlServer.ColumnOptions, Microsoft.Extensions.Configuration.IConfigurationSection, Serilog.Formatting.ITextFormatter, Microsoft.Extensions.Configuration.IConfigurationSection)'.'

When I downgraded the version to 5.3.0, its working as expected. Except that I had to change the signature of WriteTo.MSSQLServer, the latest version was expecting SinksOptions but the older version was all inline.

  • Serilog:
  • Serilog.Sinks.MSSqlServer:

Target framework and operating system:

[ ] .NET Standard 2.0

@ckadluba
Copy link
Member

ckadluba commented May 26, 2020

Hi @saisworld! Thank you for reporting. The SinkOptions methods are the new and recommended API. It was introduced in 5.4.0 but until the next major release (6.0.0) the old methods will still be supported.

https://github.com/serilog/serilog-sinks-mssqlserver/releases/tag/v324

Can you please give us a code sample that reproduces the problem?

@saisworld
Copy link
Author

Below is the code sample that I have used for creating the logger -

`

     return new LoggerConfiguration()
            .Enrich.FromLogContext()
            .Enrich.WithMachineName()
            .Enrich.WithProcessName()
            .Enrich.WithThreadId()
            .WithMinimumLogLevel(applicationLoggerSettings.ApplicationLoggerOutputSettingsCollection)
            .WriteTo.MSSqlServer(msSqlServerApplicationLoggerOutputSettings.ConnectionString,
                new SinkOptions
                {
                    TableName = msSqlServerApplicationLoggerOutputSettings.LogsTableName,
                    AutoCreateSqlTable = true
                }, columnOptions:BuildColumnOptions())


public ColumnOptions BuildColumnOptions()
    {
        var columnOptions = new ColumnOptions
        {
            TimeStamp =
            {
                ColumnName = "TimeStampUTC",
                ConvertToUtc = true,
            },
            AdditionalColumns = new Collection<SqlColumn>
            {
                new SqlColumn { DataType = SqlDbType.NChar, ColumnName = "MachineName" },
                new SqlColumn { DataType = SqlDbType.NChar, ColumnName = "ProcessName" },
                new SqlColumn { DataType = SqlDbType.NChar, ColumnName = "ThreadId" },
                new SqlColumn { DataType = SqlDbType.NChar, ColumnName = "CallerName" },
                new SqlColumn { DataType = SqlDbType.NChar, ColumnName = "SourceFile" },
                new SqlColumn { DataType = SqlDbType.NChar, ColumnName = "LineNumber" }              
            }
        };

        columnOptions.Store.Remove(StandardColumn.Properties);

        return columnOptions;
    }`

@ckadluba
Copy link
Member

Sorry for the delayed answer. Just a short update: I could reproduce the problem with a small sample program. I'll probably add this one to the sink source under the sample folder.

Investigation continues.

@ckadluba ckadluba self-assigned this May 31, 2020
@ckadluba ckadluba added the bug label May 31, 2020
@ckadluba
Copy link
Member

ckadluba commented Jun 6, 2020

I found out that the order of the parameters of the problematic configuration extension methods in the generated sink assembly for .NET Standard was different than in the source code. I don't know the exact reason why but when I ordered the parameters in the source code like i observed them in IL disassembler, the MissingMethodException disappeared.

I merged a PR to the dev branch with this fix and created a Serilog.Sinks.MSSqlServer.5.4.1-dev-00349 on nuget.org. The source now contains a NetStandardDemo now which I used to reproduce and fix the problem.

@saisworld could you please use the Serilog.Sinks.MSSqlServer.5.4.1-dev-00349 and let me know if it fixes the problem for you too?

@saisworld
Copy link
Author

saisworld commented Jun 7, 2020 via email

@saisworld
Copy link
Author

@ckadluba , I tried the nuget version Serilog.Sinks.MSSqlServer.5.4.1-dev-00349 and its working as expected. Thank you for fixing this.

@ckadluba
Copy link
Member

ckadluba commented Jun 9, 2020

@saisworld you are welcome! I'm glad this is fixed. Thank you for verifying.

@ckadluba ckadluba closed this as completed Jun 9, 2020
@rus-vladimir
Copy link

@ckadluba Hello, to me this looks broken again in 5.7.1 using MSSqlServerSinkOptions. Originally had the commented out version with SinkOptions that were passed to MSSqlServer. It was throwing Method not found: 'Serilog.LoggerConfiguration Serilog.LoggerConfigurationMSSqlServerExtensions.MSSqlServer

            //MSSqlServerSinkOptions sinkOptions = new MSSqlServerSinkOptions()
            //{
            //    TableName = "Logs",
            //    AutoCreateSqlTable = true
            //};
            return cfg.WriteTo.MSSqlServer(connectionString, tableName: "Logs", autoCreateSqlTable: true, restrictedToMinimumLevel: LogEventLevel.Information);

Reverted to 5.3 and unlined the call and everything works.

@ckadluba
Copy link
Member

ckadluba commented Sep 6, 2022

@rusanov-vladimir Can you please provide a sample program to reproduce the problem?

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

No branches or pull requests

3 participants