Skip to content

Commit 23c9d79

Browse files
authored
Merge pull request #251 from ckadluba/refactoring-cleanup-tests
Fixed deprecated NuGet properties.
2 parents 8ec8e2e + bc00ffa commit 23c9d79

26 files changed

+155
-55
lines changed

src/Serilog.Sinks.MSSqlServer/Configuration/Extensions/Hybrid/LoggerConfigurationMSSqlServerExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static class LoggerConfigurationMSSqlServerExtensions
3535
/// <summary>
3636
/// The configuration section name for app.config or web.config configuration files.
3737
/// </summary>
38-
public static string AppConfigSectionName = "MSSqlServerSettingsSection";
38+
public const string AppConfigSectionName = "MSSqlServerSettingsSection";
3939

4040
/// <summary>
4141
/// Adds a sink that writes log events to a table in a MSSqlServer database.

src/Serilog.Sinks.MSSqlServer/Configuration/Extensions/System.Configuration/LoggerConfigurationMSSqlServerExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Serilog.Sinks.MSSqlServer;
1919
using System.Configuration;
2020
using Serilog.Formatting;
21+
using System.Diagnostics.CodeAnalysis;
2122

2223
// System.Configuration support for .NET Framework 4.5.2 libraries and apps.
2324

@@ -31,6 +32,8 @@ public static class LoggerConfigurationMSSqlServerExtensions
3132
/// <summary>
3233
/// The configuration section name for app.config or web.config configuration files.
3334
/// </summary>
35+
// TODO: Make this non-static. It could cause race condition in unit tests!
36+
[SuppressMessage("Usage", "CA2211:Non-constant fields should not be visible", Justification = "Too hard to change. Accepted for now.")]
3437
public static string AppConfigSectionName = "MSSqlServerSettingsSection";
3538

3639
/// <summary>

src/Serilog.Sinks.MSSqlServer/Configuration/Implementations/SetProperty.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23

34
namespace Serilog.Sinks.MSSqlServer
45
{
@@ -22,10 +23,10 @@ public static partial class SetProperty
2223
/// </summary>
2324
public static void IfNotNull<T>(string value, PropertySetter<T> setter)
2425
{
25-
if (value == null) return;
26+
if (value == null || setter == null) return;
2627
try
2728
{
28-
T setting = (T)Convert.ChangeType(value, typeof(T));
29+
T setting = (T)Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture);
2930
setter(setting);
3031
}
3132
// don't change the property if the conversion fails

src/Serilog.Sinks.MSSqlServer/Configuration/Implementations/System.Configuration/ColumnCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected override ConfigurationElement CreateNewElement()
2828

2929
protected override object GetElementKey(ConfigurationElement element)
3030
{
31-
return ((ColumnConfig)element).ColumnName;
31+
return ((ColumnConfig)element)?.ColumnName;
3232
}
3333
}
3434
}

src/Serilog.Sinks.MSSqlServer/Configuration/Implementations/System.Configuration/SetPropertyValueOrigin.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public static partial class SetProperty
1212
/// </summary>
1313
public static void IfProvided<T>(ConfigurationElement element, string propertyName, PropertySetter<T> setter)
1414
{
15+
if (element == null)
16+
{
17+
return;
18+
}
19+
1520
var property = element.ElementInformation.Properties[propertyName];
1621
if (property.ValueOrigin == PropertyValueOrigin.Default) return;
1722
IfNotNull((string)property.Value, setter);
@@ -22,6 +27,11 @@ public static void IfProvided<T>(ConfigurationElement element, string propertyNa
2227
/// </summary>
2328
public static void IfProvidedNotEmpty<T>(ConfigurationElement element, string propertyName, PropertySetter<T> setter)
2429
{
30+
if (element == null)
31+
{
32+
return;
33+
}
34+
2535
var property = element.ElementInformation.Properties[propertyName];
2636
if (property.ValueOrigin == PropertyValueOrigin.Default) return;
2737
IfNotNullOrEmpty((string)property.Value, setter);

src/Serilog.Sinks.MSSqlServer/Configuration/Implementations/System.Configuration/StandardColumnCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected override ConfigurationElement CreateNewElement()
1414

1515
protected override object GetElementKey(ConfigurationElement element)
1616
{
17-
return ((StandardColumnConfig)element).Name;
17+
return ((StandardColumnConfig)element)?.Name;
1818
}
1919
}
2020
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This file is used by Code Analysis to maintain SuppressMessage
2+
// attributes that are applied to this project.
3+
// Project-level suppressions either have no target or are given
4+
// a specific target and scoped to a namespace, type, member, etc.
5+
6+
using System.Diagnostics.CodeAnalysis;
7+
8+
[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "Supplying string literals and not using resources is accepted within this project.", Scope = "namespaceanddescendants", Target = "Serilog.Sinks.MSSqlServer")]
9+
[assembly: SuppressMessage("Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "Too hard to change. Accepted for now.", Scope = "namespaceanddescendants", Target = "Serilog.Sinks.MSSqlServer")]
10+
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Too hard to change. Accepted for now.", Scope = "member", Target = "~M:Serilog.Sinks.MSSqlServer.MSSqlServerSinkTraits.TryChangeType(System.Object,System.Type,System.Object@)~System.Boolean")]
11+
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Too hard to change. Accepted for now.", Scope = "member", Target = "~M:Serilog.Sinks.MSSqlServer.MSSqlServerSink.EmitBatchAsync(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})~System.Threading.Tasks.Task")]
12+
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Too hard to change. Accepted for now.", Scope = "member", Target = "~M:Serilog.Sinks.MSSqlServer.MSSqlServerSinkTraits.ConvertPropertiesToXmlStructure(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{System.String,Serilog.Events.LogEventPropertyValue}})~System.String")]
13+
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Too hard to change. Accepted for now.", Scope = "member", Target = "~M:Serilog.Sinks.MSSqlServer.MSSqlServerSinkTraits.#ctor(System.String,System.String,System.String,Serilog.Sinks.MSSqlServer.ColumnOptions,System.IFormatProvider,System.Boolean,Serilog.Formatting.ITextFormatter,Serilog.Sinks.MSSqlServer.Platform.ISqlTableCreator)")]
14+
[assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "Serilog core guarantees to call Emit() with non-null logEvent parameter.", Scope = "member", Target = "~M:Serilog.Sinks.MSSqlServer.MSSqlServerAuditSink.Emit(Serilog.Events.LogEvent)")]
15+
[assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "Serilog core guarantees to call EmitBatchAsync() with non-null logEvent parameter.", Scope = "member", Target = "~M:Serilog.Sinks.MSSqlServer.MSSqlServerSink.EmitBatchAsync(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})~System.Threading.Tasks.Task")]
16+
[assembly: SuppressMessage("Design", "CA1034:Nested types should not be visible", Justification = "Cannot be changed on public classes for backward compatibility reasons.", Scope = "namespaceanddescendants", Target = "Serilog.Sinks.MSSqlServer")]
17+
[assembly: SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Cannot be changed on public classes for backward compatibility reasons.", Scope = "type", Target = "~T:Serilog.Sinks.MSSqlServer.ColumnOptions")]
18+
[assembly: SuppressMessage("Design", "CA1010:Collections should implement generic interface", Justification = "Cannot be changed on public classes for backward compatibility reasons.", Scope = "namespaceanddescendants", Target = "Serilog.Sinks.MSSqlServer")]
19+
[assembly: SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "Too hard to change. Accepted for now.", Scope = "type", Target = "~T:Serilog.LoggerConfigurationMSSqlServerExtensions")]
20+
[assembly: SuppressMessage("Performance", "CA1822: Member AllowNull does not access instance data and can be marked as static (Shared in VisualBasic)", Justification = "Cannot be changed on public classes for backward compatibility reasons.", Scope = "member", Target = "~P:Serilog.Sinks.MSSqlServer.ColumnOptions.IdColumnOptions.AllowNull")]
20.4 KB
Loading

src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
1414
<PackageId>Serilog.Sinks.MSSqlServer</PackageId>
1515
<PackageTags>serilog;sinks;mssqlserver</PackageTags>
16-
<PackageIconUrl>http://serilog.net/images/serilog-sink-nuget.png</PackageIconUrl>
16+
<PackageIcon>serilog-sink-nuget.png</PackageIcon>
1717
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-mssqlserver</PackageProjectUrl>
18-
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
18+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1919
<RepositoryUrl>https://github.com/serilog/serilog-sinks-mssqlserver</RepositoryUrl>
2020
<RepositoryType>git</RepositoryType>
2121
<RuntimeIdentifiers>win</RuntimeIdentifiers>
@@ -26,6 +26,10 @@
2626

2727
<ItemGroup>
2828
<!-- Whenever these are updated, also update versions in packages.config for net452 -->
29+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
30+
<PrivateAssets>all</PrivateAssets>
31+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
32+
</PackageReference>
2933
<PackageReference Include="Serilog" Version="2.5.0" />
3034
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.1.1" />
3135
</ItemGroup>
@@ -45,7 +49,7 @@
4549
<None Include="Configuration\Implementations\System.Configuration\**\*.*" />
4650
<!-- ItemGroups below with TFM conditions will re-include the compile targets -->
4751
</ItemGroup>
48-
52+
4953
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
5054
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
5155
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
@@ -75,4 +79,8 @@
7579
<Compile Include="Configuration\Implementations\System.Configuration\**\*.cs" />
7680
</ItemGroup>
7781

82+
<ItemGroup>
83+
<None Include="Images\serilog-sink-nuget.png" Pack="true" PackagePath="" />
84+
</ItemGroup>
85+
7886
</Project>

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/MSSqlServerAuditSink.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public MSSqlServerAuditSink(
5050
string schemaName = "dbo",
5151
ITextFormatter logEventFormatter = null)
5252
{
53-
columnOptions.FinalizeConfigurationForSinkConstructor();
53+
columnOptions?.FinalizeConfigurationForSinkConstructor();
5454

5555
if (columnOptions != null)
5656
{

0 commit comments

Comments
 (0)