Skip to content

Commit 2a465e4

Browse files
authored
Merge pull request #265 from ckadluba/azure-managed-identities
New interfaces and support for Azure Managed Identities
2 parents 000cd34 + d25ccc1 commit 2a465e4

File tree

55 files changed

+2402
-474
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2402
-474
lines changed

README.md

Lines changed: 119 additions & 47 deletions
Large diffs are not rendered by default.

sample/AppConfigDemo/App.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
88
</startup>
99
<MSSqlServerSettingsSection>
10+
11+
<BatchPostingLimit Value="13" />
12+
<BatchPeriod Value="00:00:15" />
13+
1014
<AddStandardColumns>
1115
<add Name="LogEvent" />
1216
</AddStandardColumns>
1317
<RemoveStandardColumns>
1418
<remove Name="Properties" />
1519
</RemoveStandardColumns>
1620
<TimeStamp ColumnName="TimeStampAlternative" ConvertToUtc="true" />
21+
1722
</MSSqlServerSettingsSection>
1823
<runtime>
1924
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

sample/AppConfigDemo/Program.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Serilog;
44
using Serilog.Events;
55
using Serilog.Sinks.MSSqlServer;
6+
using Serilog.Sinks.MSSqlServer.Sinks.MSSqlServer.Options;
67

78
namespace AppConfigDemo
89
{
@@ -14,17 +15,34 @@ public static class Program
1415

1516
public static void Main()
1617
{
18+
// Legacy interace - do not use this anymore
19+
//Log.Logger = new LoggerConfiguration().WriteTo
20+
// .MSSqlServer(
21+
// connectionString: _connectionString,
22+
// tableName: _tableName,
23+
// restrictedToMinimumLevel: LogEventLevel.Debug,
24+
// batchPostingLimit: MSSqlServerSink.DefaultBatchPostingLimit,
25+
// period: null,
26+
// formatProvider: null,
27+
// autoCreateSqlTable: true,
28+
// columnOptions: null,
29+
// schemaName: _schemaName,
30+
// logEventFormatter: null)
31+
// .CreateLogger();
32+
33+
// New SinkOptions based interface
1734
Log.Logger = new LoggerConfiguration().WriteTo
1835
.MSSqlServer(
1936
connectionString: _connectionString,
20-
tableName: _tableName,
37+
sinkOptions: new SinkOptions
38+
{
39+
TableName = _tableName,
40+
SchemaName = _schemaName,
41+
AutoCreateSqlTable = true
42+
},
2143
restrictedToMinimumLevel: LogEventLevel.Debug,
22-
batchPostingLimit: MSSqlServerSink.DefaultBatchPostingLimit,
23-
period: null,
2444
formatProvider: null,
25-
autoCreateSqlTable: true,
2645
columnOptions: null,
27-
schemaName: _schemaName,
2846
logEventFormatter: null)
2947
.CreateLogger();
3048

sample/CombinedConfigDemo/Program.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading;
33
using Microsoft.Extensions.Configuration;
44
using Serilog;
5+
using Serilog.Sinks.MSSqlServer.Sinks.MSSqlServer.Options;
56

67
namespace CombinedConfigDemo
78
{
@@ -20,15 +21,32 @@ public static void Main()
2021
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
2122
.Build();
2223
var columnOptionsSection = configuration.GetSection("Serilog:ColumnOptions");
24+
var sinkOptionsSection = configuration.GetSection("Serilog:SinkOptions");
2325

26+
// Legacy interace - do not use this anymore
27+
//Log.Logger = new LoggerConfiguration()
28+
// .WriteTo.MSSqlServer(
29+
// connectionString: _connectionStringName,
30+
// tableName: _tableName,
31+
// appConfiguration: configuration,
32+
// autoCreateSqlTable: true,
33+
// columnOptionsSection: columnOptionsSection,
34+
// schemaName: _schemaName)
35+
// .CreateLogger();
36+
37+
// New SinkOptions based interface
2438
Log.Logger = new LoggerConfiguration()
2539
.WriteTo.MSSqlServer(
2640
connectionString: _connectionStringName,
27-
tableName: _tableName,
41+
sinkOptions: new SinkOptions
42+
{
43+
TableName = _tableName,
44+
SchemaName = _schemaName,
45+
AutoCreateSqlTable = true
46+
},
47+
sinkOptionsSection: sinkOptionsSection,
2848
appConfiguration: configuration,
29-
autoCreateSqlTable: true,
30-
columnOptionsSection: columnOptionsSection,
31-
schemaName: _schemaName)
49+
columnOptionsSection: columnOptionsSection)
3250
.CreateLogger();
3351

3452
Log.Information("Hello {Name} from thread {ThreadId}", Environment.GetEnvironmentVariable("USERNAME"), Thread.CurrentThread.ManagedThreadId);

sample/CombinedConfigDemo/appsettings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"LogDatabase": "Server=localhost;Database=LogTest;Integrated Security=SSPI;"
1111
},
1212
"Serilog": {
13+
"SinkOptions": {
14+
"batchPostingLimit": 5,
15+
"batchPeriod": "00:00:15"
16+
},
1317
"ColumnOptions": {
1418
"addStandardColumns": [ "LogEvent" ],
1519
"removeStandardColumns": [ "MessageTemplate", "Properties" ],

sample/CustomLogEventFormatterDemo/Program.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading;
33
using Serilog;
44
using Serilog.Sinks.MSSqlServer;
5+
using Serilog.Sinks.MSSqlServer.Sinks.MSSqlServer.Options;
56

67
namespace CustomLogEventFormatterDemo
78
{
@@ -16,18 +17,37 @@ public static void Main()
1617
var options = new ColumnOptions();
1718
options.Store.Add(StandardColumn.LogEvent);
1819
var customFormatter = new FlatLogEventFormatter();
20+
21+
// Legacy interace - do not use this anymore
22+
//Log.Logger = new LoggerConfiguration()
23+
// .WriteTo.MSSqlServer(_connectionString,
24+
// _tableName,
25+
// appConfiguration: null,
26+
// restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Verbose,
27+
// batchPostingLimit: 50,
28+
// period: null,
29+
// formatProvider: null,
30+
// autoCreateSqlTable: true,
31+
// columnOptions: options,
32+
// columnOptionsSection: null,
33+
// schemaName: _schemaName,
34+
// logEventFormatter: customFormatter)
35+
// .CreateLogger();
36+
37+
// New SinkOptions based interface
1938
Log.Logger = new LoggerConfiguration()
2039
.WriteTo.MSSqlServer(_connectionString,
21-
_tableName,
40+
sinkOptions: new SinkOptions
41+
{
42+
TableName = _tableName,
43+
SchemaName = _schemaName,
44+
AutoCreateSqlTable = true
45+
},
2246
appConfiguration: null,
2347
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Verbose,
24-
batchPostingLimit: 50,
25-
period: null,
2648
formatProvider: null,
27-
autoCreateSqlTable: true,
2849
columnOptions: options,
2950
columnOptionsSection: null,
30-
schemaName: _schemaName,
3151
logEventFormatter: customFormatter)
3252
.CreateLogger();
3353

sample/WorkerServiceDemo/appsettings.json

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,31 @@
1414
"Name": "MSSqlServer",
1515
"Args": {
1616
"connectionString": "Server=localhost;Database=LogTest;Integrated Security=SSPI;",
17-
"tableName": "LogEvents",
17+
"sinkOptionsSection": {
18+
"tableName": "LogEvents",
19+
"autoCreateSqlTable": true,
20+
"useAzureManagedIdentity": false,
21+
"azureServiceTokenProviderResource": "TestAzureServiceTokenProviderResource"
22+
},
23+
"restrictedToMinimumLevel": "Information",
24+
"columnOptionsSection": {
25+
"addStandardColumns": [ "LogEvent" ],
26+
"removeStandardColumns": [ "MessageTemplate", "Properties" ],
27+
"timeStamp": {
28+
"columnName": "Timestamp",
29+
"convertToUtc": false
30+
}
31+
},
32+
"logEventFormatter": "WorkerServiceDemo.CustomLogEventFormatter::Formatter, WorkerServiceDemo"
33+
}
34+
}
35+
],
36+
"AuditTo": [
37+
{
38+
"Name": "MSSqlServer",
39+
"Args": {
40+
"connectionString": "Server=localhost;Database=LogTest;Integrated Security=SSPI;",
41+
"tableName": "LogEventsAudit",
1842
"columnOptionsSection": {
1943
"addStandardColumns": [ "LogEvent" ],
2044
"removeStandardColumns": [ "MessageTemplate", "Properties" ],
@@ -25,7 +49,11 @@
2549
},
2650
"autoCreateSqlTable": true,
2751
"restrictedToMinimumLevel": "Information",
28-
"logEventFormatter": "WorkerServiceDemo.CustomLogEventFormatter::Formatter, WorkerServiceDemo"
52+
"logEventFormatter": "WorkerServiceDemo.CustomLogEventFormatter::Formatter, WorkerServiceDemo",
53+
"sinkOptionsSection": {
54+
"useAzureManagedIdentity": false,
55+
"azureServiceTokenProviderResource": "TestAuditAzureServiceTokenProviderResource"
56+
}
2957
}
3058
}
3159
]

0 commit comments

Comments
 (0)