Reputation: 2102
I am attempting to add an additional column to my logging in SQL Server. In the examples, they give something very similar to the following:
var columnOptions = new ColumnOptions
{
AdditionalDataColumns = new Collection<SqlColumn>
{
new SqlColumn { DataType = SqlDbType.NVarChar, DataLength = 20, ColumnName = "B" }
}
}
The problem that I am having is that my compiler keeps complaining about the SqlColumn
type usage saying that it is unknown. I am using .Net 4.6.1. What do I need to add to my using? I have the following already:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.IdentityModel.Tokens;
using System.Linq;
using System.Web.Http;
using System.Web.Http.ExceptionHandling;
using System.Net.Http.Formatting;
using Dapper;
using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Microsoft.Owin.Cors;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Jwt;
using Newtonsoft.Json.Serialization;
using Owin;
using Serilog;
using Serilog.Filters;
using Serilog.Sinks.MSSqlServer;
using SerilogWeb.Classic.WebApi;
EDIT
I have just attempted building an entire new web api project, and the following code also will not work, for some reason I cannot access the SqlColumn type. Note that the error is that the type doesn't exist on the namespace (not an error due to the constructor).
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Owin;
using Owin;
using Serilog;
using Serilog.Sinks.MSSqlServer;
[assembly: OwinStartup(typeof(TestProject.Startup))]
namespace TestProject
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
var x = new Serilog.Sinks.MSSqlServer.SqlColumn();
}
}
}
Upvotes: 0
Views: 1388
Reputation: 7865
You will need to Update Serilog.Sinks.MSSqlServer to prereleased version 5.1.3-dev-00232 as its not exist in version 5.1.2
Install-Package Serilog.Sinks.MSSqlServer -Version 5.1.3-dev-00232
Or you can add column using DataColumn
type in version 5.1.2 as below
var columnOptions = new ColumnOptions
{
AdditionalDataColumns = new Collection<DataColumn>
{
new DataColumn {DataType = typeof (string), ColumnName = "User"},
new DataColumn {DataType = typeof (string), ColumnName = "Other"},
}
};
var log = new LoggerConfiguration()
.WriteTo.MSSqlServer(@"Server=.\SQLEXPRESS;Database=LogEvents;Trusted_Connection=True;", "Logs", columnOptions: columnOptions)
.CreateLogger();
Upvotes: 4