serilog-mssql / serilog-sinks-mssqlserver

A Serilog sink that writes events to Microsoft SQL Server and Azure SQL
Apache License 2.0
280 stars 148 forks source link

How to map a LogEventProperty to a MSSQL column #195

Closed avelinoruiz closed 4 years ago

avelinoruiz commented 5 years ago

Hello,

I am using Serilog to log events to a mssqlserver table that has a different column's name than the property's.

How can I map the following property to the column "machineName" defined in a table?

LogEventProperty("hostName", new ScalarValue(Environment.MachineName))

Thank you

If you are opening a feature request, you can ignore this template. Bug reports and requests for assistance usually require the same basic information described below. This will help us more quickly reproduce and investigate the problem you're reporting. (If you are using Serilog.Sinks.MSSqlServerCore, that package is deprecated, please switch to Serilog.Sinks.MSSqlServer before reporting an issue.)

Please clearly describe what the SQL Sink is doing incorrectly:

Please clearly describe the expected behavior:

List the names and versions of all Serilog packages used in the project:

Target framework and operating system:

[ ] .NET Core 2.0 [ ] .NET Framework 4.7 [ ] .NET Framework 4.6.x [ ] .NET Framework 4.5.x OS:

Provide a simple reproduction of your Serilog configuration code:

Provide a simple reproduction of your Serilog configuration file, if any:

Provide a simple reproduction of your application code:

ckadluba commented 4 years ago

Hi @avelinoruiz. Thanks for getting in touch and sorry for the late answer.

The sink maps custom properties always to database columns of the same name. Unfortunately there is no way to map them to a column with a name that differs from the property name.

You could define a Serilog enricher for your MachineName property and provide the value in that enricher.

ckadluba commented 4 years ago

A small update on this.

This issue is a duplicate of issue #182 and since there seems to be some demand for this enhancement, we have now plans to implement it.