Skip to content

Commit 548d9df

Browse files
committed
Merged
2 parents 19d1e33 + 64b9917 commit 548d9df

File tree

63 files changed

+4369
-1032
lines changed

Some content is hidden

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

63 files changed

+4369
-1032
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Bug Report / Support Request Template
2+
--------------------------------------
3+
If you are opening a feature request, you can ignore this template. Bug reports and requests for assistance usually require the same basic information described below. This will help us more quickly reproduce and investigate the problem you're reporting. (If you are using Serilog.Sinks.MSSqlServerCore, that package is deprecated, please switch to Serilog.Sinks.MSSqlServer before reporting an issue.)
4+
5+
>> Please clearly describe what the SQL Sink is doing incorrectly:
6+
7+
>> Please clearly describe the expected behavior:
8+
9+
>> List the names and versions of all Serilog packages used in the project:
10+
11+
- Serilog:
12+
- Serilog.Sinks.MSSqlServer:
13+
- (configuration, etc.)
14+
15+
>> Target framework and operating system:
16+
17+
[ ] .NET Core 2.0
18+
[ ] .NET Framework 4.7
19+
[ ] .NET Framework 4.6.x
20+
[ ] .NET Framework 4.5.x
21+
OS:
22+
23+
>> Provide a *simple* reproduction of your Serilog configuration code:
24+
25+
>> Provide a *simple* reproduction of your Serilog configuration file, if any:
26+
27+
>> Provide a *simple* reproduction of your application code:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,4 @@ UpgradeLog*.htm
183183
FakesAssemblies/
184184
/.vs/serilog-sinks-mssqlserver/v15/sqlite3
185185
/.vs/serilog-sinks-mssqlserver/v15/Server/sqlite3
186+
/.vs

README.md

Lines changed: 568 additions & 80 deletions
Large diffs are not rendered by default.

appveyor.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ build_script:
99
test: off
1010
artifacts:
1111
- path: artifacts/Serilog.*.nupkg
12+
only_commits:
13+
files:
14+
- serilog-sinks-mssqlserver.sln
15+
- src/Serilog.Sinks.MSSqlServer/
16+
- Build.ps1
17+
- assets/
18+
- test/Serilog.Sinks.MSSqlServer.Tests/
1219
deploy:
1320
- provider: NuGet
1421
api_key:
15-
secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x
22+
secure: N59tiJECUYpip6tEn0xvdmDAEiP9SIzyLEFLpwiigm/8WhJvBNs13QxzT1/3/JW/
1623
skip_symbols: true
1724
on:
1825
branch: /^(master|dev)$/

src/Serilog.Sinks.MSSqlServer/Configuration/ColumnConfig.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
// Copyright 2014 Serilog Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
using Serilog.Configuration;
17+
using Serilog.Events;
18+
using Serilog.Sinks.MSSqlServer;
19+
using Microsoft.Extensions.Configuration;
20+
using System.Configuration;
21+
using Serilog.Debugging;
22+
23+
// The "Hybrid" configuration system supports both Microsoft.Extensions.Configuration and System.Configuration.
24+
// This is necessary because .NET Framework 4.6.1+ and .NET Core 2.0+ apps support both approaches, whereas the
25+
// older .NET Framework 4.5.2 only supports System.Configuration and .NET Standard 2.0 only supports M.E.C.
26+
27+
namespace Serilog
28+
{
29+
/// <summary>
30+
/// Adds the WriteTo.MSSqlServer() extension method to <see cref="LoggerConfiguration"/>.
31+
/// </summary>
32+
public static class LoggerConfigurationMSSqlServerExtensions
33+
{
34+
/// <summary>
35+
/// The configuration section name for app.config or web.config configuration files.
36+
/// </summary>
37+
public static string AppConfigSectionName = "MSSqlServerSettingsSection";
38+
39+
/// <summary>
40+
/// Adds a sink that writes log events to a table in a MSSqlServer database.
41+
/// Create a database and execute the table creation script found here
42+
/// https://gist.github.com/mivano/10429656
43+
/// or use the autoCreateSqlTable option.
44+
/// </summary>
45+
/// <param name="loggerConfiguration">The logger configuration.</param>
46+
/// <param name="connectionString">The connection string to the database where to store the events.</param>
47+
/// <param name="tableName">Name of the table to store the events in.</param>
48+
/// <param name="appConfiguration">Additional application-level configuration. Required if connectionString is a name.</param>
49+
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
50+
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
51+
/// <param name="period">The time to wait between checking for event batches.</param>
52+
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
53+
/// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
54+
/// <param name="columnOptions">An externally-modified group of column settings</param>
55+
/// <param name="columnOptionsSection">A config section defining various column settings</param>
56+
/// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
57+
/// <returns>Logger configuration, allowing configuration to continue.</returns>
58+
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
59+
public static LoggerConfiguration MSSqlServer(
60+
this LoggerSinkConfiguration loggerConfiguration,
61+
string connectionString,
62+
string tableName,
63+
IConfiguration appConfiguration = null,
64+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
65+
int batchPostingLimit = MSSqlServerSink.DefaultBatchPostingLimit,
66+
TimeSpan? period = null,
67+
IFormatProvider formatProvider = null,
68+
bool autoCreateSqlTable = false,
69+
ColumnOptions columnOptions = null,
70+
IConfigurationSection columnOptionsSection = null,
71+
string schemaName = "dbo"
72+
)
73+
{
74+
if(loggerConfiguration == null)
75+
throw new ArgumentNullException("loggerConfiguration");
76+
77+
var defaultedPeriod = period ?? MSSqlServerSink.DefaultPeriod;
78+
var colOpts = columnOptions ?? new ColumnOptions();
79+
var connStr = connectionString;
80+
81+
if (ConfigurationManager.GetSection(AppConfigSectionName) is MSSqlServerConfigurationSection serviceConfigSection)
82+
{
83+
colOpts = ApplySystemConfiguration.ConfigureColumnOptions(serviceConfigSection, colOpts);
84+
connStr = ApplySystemConfiguration.GetConnectionString(connStr);
85+
86+
if (appConfiguration != null || columnOptionsSection != null)
87+
SelfLog.WriteLine("Warning: Both System.Configuration (app.config or web.config) and Microsoft.Extensions.Configuration are being applied to the MSSQLServer sink.");
88+
}
89+
90+
if (appConfiguration != null || columnOptionsSection != null)
91+
{
92+
connStr = ApplyMicrosoftExtensionsConfiguration.GetConnectionString(connStr, appConfiguration);
93+
colOpts = ApplyMicrosoftExtensionsConfiguration.ConfigureColumnOptions(colOpts, columnOptionsSection);
94+
}
95+
96+
return loggerConfiguration.Sink(
97+
new MSSqlServerSink(
98+
connStr,
99+
tableName,
100+
batchPostingLimit,
101+
defaultedPeriod,
102+
formatProvider,
103+
autoCreateSqlTable,
104+
colOpts,
105+
schemaName
106+
),
107+
restrictedToMinimumLevel);
108+
}
109+
110+
/// <summary>
111+
/// Adds a sink that writes log events to a table in a MSSqlServer database.
112+
/// </summary>
113+
/// <param name="loggerAuditSinkConfiguration">The logger configuration.</param>
114+
/// <param name="connectionString">The connection string to the database where to store the events.</param>
115+
/// <param name="tableName">Name of the table to store the events in.</param>
116+
/// <param name="appConfiguration">Additional application-level configuration. Required if connectionString is a name.</param>
117+
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
118+
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
119+
/// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
120+
/// <param name="columnOptions">An externally-modified group of column settings</param>
121+
/// <param name="columnOptionsSection">A config section defining various column settings</param>
122+
/// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
123+
/// <returns>Logger configuration, allowing configuration to continue.</returns>
124+
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
125+
public static LoggerConfiguration MSSqlServer(
126+
this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
127+
string connectionString,
128+
string tableName,
129+
IConfiguration appConfiguration = null,
130+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
131+
IFormatProvider formatProvider = null,
132+
bool autoCreateSqlTable = false,
133+
ColumnOptions columnOptions = null,
134+
IConfigurationSection columnOptionsSection = null,
135+
string schemaName = "dbo"
136+
)
137+
{
138+
if(loggerAuditSinkConfiguration == null)
139+
throw new ArgumentNullException("loggerAuditSinkConfiguration");
140+
141+
var colOpts = columnOptions ?? new ColumnOptions();
142+
var connStr = connectionString;
143+
144+
if (ConfigurationManager.GetSection(AppConfigSectionName) is MSSqlServerConfigurationSection serviceConfigSection)
145+
{
146+
colOpts = ApplySystemConfiguration.ConfigureColumnOptions(serviceConfigSection, colOpts);
147+
connStr = ApplySystemConfiguration.GetConnectionString(connStr);
148+
149+
if (appConfiguration != null || columnOptionsSection != null)
150+
SelfLog.WriteLine("Warning: Both System.Configuration (app.config or web.config) and Microsoft.Extensions.Configuration are being applied to the MSSQLServer sink.");
151+
}
152+
153+
if (appConfiguration != null || columnOptionsSection != null)
154+
{
155+
connStr = ApplyMicrosoftExtensionsConfiguration.GetConnectionString(connStr, appConfiguration);
156+
colOpts = ApplyMicrosoftExtensionsConfiguration.ConfigureColumnOptions(colOpts, columnOptionsSection);
157+
}
158+
159+
return loggerAuditSinkConfiguration.Sink(
160+
new MSSqlServerAuditSink(
161+
connStr,
162+
tableName,
163+
formatProvider,
164+
autoCreateSqlTable,
165+
colOpts,
166+
schemaName
167+
),
168+
restrictedToMinimumLevel);
169+
}
170+
}
171+
}

0 commit comments

Comments
 (0)