Adding Application.Logs WWI sample

Added a table required to demo LOB support in CLUSTERE COLUMNSOTRE INDEXes.
Scenario is application logging. Applicaiton pushes log events that have large descriptions into the LOB column in CCI table. Table is compliant wiht Serilog logger for .Net and can be direclty used as a target for MSSQL Serilog sink:

In applicaition should be added the following changes to integrate serilog:
1. Download Serilog and Serilog.MSSQL.sink NuGet packages
2. Add the following packages:
using Serilog;
using Serilog.Sinks.MSSqlServer;

3. Configure logger:
var columnOptions = new Serilog.Sinks.MSSqlServer.ColumnOptions();
// Don't include the Properties XML column.
columnOptions.Store.Remove(StandardColumn.Properties);
columnOptions.Store.Remove(StandardColumn.MessageTemplate);
columnOptions.Store.Remove(StandardColumn.Exception);
// Do include the log event data as JSON.
columnOptions.Store.Add(StandardColumn.LogEvent);

var logger = new LoggerConfiguration()
                .WriteTo
                .MSSqlServer(   ConnString, "Logs", schemaName: "Application",
                                autoCreateSqlTable: false,
                                columnOptions: columnOptions
                                )
                .CreateLogger());

4. Log events:
var position = new { Latitude = 25, Longitude = 134 };
var elapsedMs = 34;

log.Information("Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);
log.Error(new IndexOutOfRangeException("Test"), "Error while processing {@Position} in {Elapsed:000} ms.", position, elapsedMs);
This commit is contained in:
Jovan Popovic
2018-09-07 16:10:10 +02:00
parent 4a6c5c24b3
commit 828dd93d1e
2 changed files with 40 additions and 1 deletions
@@ -0,0 +1,38 @@
CREATE TABLE [Application].[Logs](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Message] [nvarchar](max) NULL,
[Level] [nvarchar](128) NULL,
[TimeStamp] [datetime] NOT NULL,
[LogEvent] [nvarchar](max) NULL,
INDEX cci CLUSTERED COLUMNSTORE
)
GO
GO
EXECUTE sp_addextendedproperty @name = N'Description', @value = 'CLUSTERED COLUMNSTORE INDEX that compress application log.', @level0type = N'SCHEMA', @level0name = N'Application', @level1type = N'TABLE', @level1name = N'Logs', @level2type = N'INDEX', @level2name = N'cci';
GO
EXECUTE sp_addextendedproperty @name = N'Description', @value = N'Application logs that are stored in database', @level0type = N'SCHEMA', @level0name = N'Application', @level1type = N'TABLE', @level1name = N'Logs';
GO
EXECUTE sp_addextendedproperty @name = N'Description', @value = 'Numeric ID of a log entry', @level0type = N'SCHEMA', @level0name = N'Application', @level1type = N'TABLE', @level1name = N'Logs', @level2type = N'COLUMN', @level2name = N'Id';
GO
EXECUTE sp_addextendedproperty @name = N'Description', @value = 'Logged message', @level0type = N'SCHEMA', @level0name = N'Application', @level1type = N'TABLE', @level1name = N'Logs', @level2type = N'COLUMN', @level2name = N'Message';
GO
EXECUTE sp_addextendedproperty @name = N'Description', @value = 'Severity of the log entry', @level0type = N'SCHEMA', @level0name = N'Application', @level1type = N'TABLE', @level1name = N'Logs', @level2type = N'COLUMN', @level2name = N'Level';
GO
EXECUTE sp_addextendedproperty @name = N'Description', @value = 'Time when the record is logged', @level0type = N'SCHEMA', @level0name = N'Application', @level1type = N'TABLE', @level1name = N'Logs', @level2type = N'COLUMN', @level2name = N'TimeStamp';
GO
EXECUTE sp_addextendedproperty @name = N'Description', @value = 'Details about the logged event', @level0type = N'SCHEMA', @level0name = N'Application', @level1type = N'TABLE', @level1name = N'Logs', @level2type = N'COLUMN', @level2name = N'LogEvent';
@@ -8,7 +8,7 @@
<SchemaVersion>2.0</SchemaVersion>
<ProjectVersion>4.1</ProjectVersion>
<ProjectGuid>{9e972c93-0716-4442-97fc-72c52c2c5aaa}</ProjectGuid>
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql130DatabaseSchemaProvider</DSP>
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql140DatabaseSchemaProvider</DSP>
<OutputType>Database</OutputType>
<RootPath>
</RootPath>
@@ -309,6 +309,7 @@
<AnsiNulls>On</AnsiNulls>
<QuotedIdentifier>On</QuotedIdentifier>
</Build>
<Build Include="Application\Tables\Logs.sql" />
<Build Include="Sales\Tables\SpecialDeals.sql">
<AnsiNulls>On</AnsiNulls>
<QuotedIdentifier>On</QuotedIdentifier>