-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #524 from serilog-mssql/dev
Release 6.6.0
- Loading branch information
Showing
24 changed files
with
303 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s.MSSqlServer/Configuration/Extensions/Hybrid/LoggerConfigurationMSSqlServerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Extensions/Microsoft.Extensions.Configuration/LoggerConfigurationMSSqlServerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/MSSqlServerAuditSink.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/MSSqlServerSink.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Output/IXmlPropertyFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Output/JsonLogEventFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Platform/SqlInsertStatementWriter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Serilog.Debugging; | ||
using Serilog.Events; | ||
using Serilog.Sinks.MSSqlServer.Output; | ||
using static System.FormattableString; | ||
|
||
namespace Serilog.Sinks.MSSqlServer.Platform | ||
{ | ||
internal class SqlInsertStatementWriter : ISqlBulkBatchWriter, ISqlLogEventWriter | ||
{ | ||
private readonly string _tableName; | ||
private readonly string _schemaName; | ||
private readonly ISqlConnectionFactory _sqlConnectionFactory; | ||
private readonly ILogEventDataGenerator _logEventDataGenerator; | ||
|
||
public SqlInsertStatementWriter( | ||
string tableName, | ||
string schemaName, | ||
ISqlConnectionFactory sqlConnectionFactory, | ||
ILogEventDataGenerator logEventDataGenerator) | ||
{ | ||
_tableName = tableName ?? throw new ArgumentNullException(nameof(tableName)); | ||
_schemaName = schemaName ?? throw new ArgumentNullException(nameof(schemaName)); | ||
_sqlConnectionFactory = sqlConnectionFactory ?? throw new ArgumentNullException(nameof(sqlConnectionFactory)); | ||
_logEventDataGenerator = logEventDataGenerator ?? throw new ArgumentNullException(nameof(logEventDataGenerator)); | ||
} | ||
|
||
public Task WriteBatch(IEnumerable<LogEvent> events, DataTable dataTable) => WriteBatch(events); | ||
|
||
public void WriteEvent(LogEvent logEvent) => WriteBatch(new[] { logEvent }).GetAwaiter().GetResult(); | ||
|
||
public async Task WriteBatch(IEnumerable<LogEvent> events) | ||
{ | ||
try | ||
{ | ||
using (var cn = _sqlConnectionFactory.Create()) | ||
{ | ||
await cn.OpenAsync().ConfigureAwait(false); | ||
|
||
foreach (var logEvent in events) | ||
{ | ||
using (var command = cn.CreateCommand()) | ||
{ | ||
command.CommandType = CommandType.Text; | ||
|
||
var fieldList = new StringBuilder(Invariant($"INSERT INTO [{_schemaName}].[{_tableName}] (")); | ||
var parameterList = new StringBuilder(") VALUES ("); | ||
|
||
var index = 0; | ||
foreach (var field in _logEventDataGenerator.GetColumnsAndValues(logEvent)) | ||
{ | ||
if (index != 0) | ||
{ | ||
fieldList.Append(','); | ||
parameterList.Append(','); | ||
} | ||
|
||
fieldList.Append(Invariant($"[{field.Key}]")); | ||
parameterList.Append("@P"); | ||
parameterList.Append(index); | ||
|
||
command.AddParameter(Invariant($"@P{index}"), field.Value); | ||
|
||
index++; | ||
} | ||
|
||
parameterList.Append(')'); | ||
fieldList.Append(parameterList); | ||
|
||
command.CommandText = fieldList.ToString(); | ||
|
||
await command.ExecuteNonQueryAsync().ConfigureAwait(false); | ||
} | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
SelfLog.WriteLine("Unable to write log event to the database due to following error: {0}", ex); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
78 changes: 0 additions & 78 deletions
78
src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Platform/SqlLogEventWriter.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.