Skip to content

Commit 828dd93

Browse files
committed
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);
1 parent 4a6c5c2 commit 828dd93

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
CREATE TABLE [Application].[Logs](
2+
[Id] [int] IDENTITY(1,1) NOT NULL,
3+
[Message] [nvarchar](max) NULL,
4+
[Level] [nvarchar](128) NULL,
5+
[TimeStamp] [datetime] NOT NULL,
6+
[LogEvent] [nvarchar](max) NULL,
7+
INDEX cci CLUSTERED COLUMNSTORE
8+
)
9+
GO
10+
11+
12+
GO
13+
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';
14+
15+
16+
GO
17+
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';
18+
19+
20+
GO
21+
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';
22+
23+
24+
GO
25+
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';
26+
27+
28+
GO
29+
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';
30+
31+
32+
GO
33+
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';
34+
35+
36+
GO
37+
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';
38+

samples/databases/wide-world-importers/wwi-ssdt/wwi-ssdt/WideWorldImporters.sqlproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<SchemaVersion>2.0</SchemaVersion>
99
<ProjectVersion>4.1</ProjectVersion>
1010
<ProjectGuid>{9e972c93-0716-4442-97fc-72c52c2c5aaa}</ProjectGuid>
11-
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql130DatabaseSchemaProvider</DSP>
11+
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql140DatabaseSchemaProvider</DSP>
1212
<OutputType>Database</OutputType>
1313
<RootPath>
1414
</RootPath>
@@ -309,6 +309,7 @@
309309
<AnsiNulls>On</AnsiNulls>
310310
<QuotedIdentifier>On</QuotedIdentifier>
311311
</Build>
312+
<Build Include="Application\Tables\Logs.sql" />
312313
<Build Include="Sales\Tables\SpecialDeals.sql">
313314
<AnsiNulls>On</AnsiNulls>
314315
<QuotedIdentifier>On</QuotedIdentifier>

0 commit comments

Comments
 (0)