我试图在我的SQL Server日志中添加一个额外的列。在示例中,它们提供了与以下内容非常相似的内容:
var columnOptions = new ColumnOptions
{
AdditionalDataColumns = new Collection<SqlColumn>
{
new SqlColumn { DataType = SqlDbType.NVarChar, DataLength = 20, ColumnName = "B" }
}
}
我遇到的问题是我的编译器一直抱怨SqlColumn
类型的使用说它是未知的。我正在使用.Net 4.6.1。我需要添加到我的使用中?我已经拥有以下内容:
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;
编辑
我刚刚尝试构建一个全新的web api项目,以下代码也不起作用,由于某种原因我无法访问SqlColumn类型。请注意,错误是命名空间上不存在该类型(不是由于构造函数而导致的错误)。
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();
}
}
}
您需要将Serilog.Sinks.MSSqlServer更新为预先版本的5.1.3-dev-00232,因为它在版本5.1.2中不存在
Install-Package Serilog.Sinks.MSSqlServer -Version 5.1.3-dev-00232
或者您可以使用版本5.1.2中的DataColumn
类型添加列,如下所示
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();