简体   繁体   English

Serilog MSSQL Sink SqlColumn数据类型

[英]Serilog mssql sink SqlColumn data type

I am attempting to add an additional column to my logging in SQL Server. 我正在尝试在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. 我遇到的问题是我的编译器不断抱怨SqlColumn类型的用法,说它是未知的。 I am using .Net 4.6.1. 我正在使用.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. 我刚刚尝试构建一个全新的Web api项目,并且由于某些原因我无法访问SqlColumn类型,因此以下代码也将不起作用。 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();
        }
    }
}

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 您将需要将Serilog.Sinks.MSSqlServer更新到预发行的版本5.1.3-dev- 00232 ,因为它在版本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 或者,您可以在版本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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM