Skip to content

Commit fb3b0fc

Browse files
author
Tsar Nikolay
committed
Add FxCop.
Fix CA2000, CA2237, CA3075
1 parent 2105ec8 commit fb3b0fc

File tree

10 files changed

+669
-540
lines changed

10 files changed

+669
-540
lines changed

log4net.ruleset

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RuleSet Name="Flexberry Rules" Description="Rules for apache log4net project." ToolsVersion="16.0">
3+
<Localization ResourceAssembly="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.dll" ResourceBaseName="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.Localized">
4+
<Name Resource="MinimumRecommendedRules_Name" />
5+
<Description Resource="MinimumRecommendedRules_Description" />
6+
</Localization>
7+
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
8+
<Rule Id="CA1001" Action="Warning" />
9+
<Rule Id="CA1009" Action="Warning" />
10+
<Rule Id="CA1016" Action="Warning" />
11+
<Rule Id="CA1033" Action="Warning" />
12+
<Rule Id="CA1049" Action="Warning" />
13+
<Rule Id="CA1060" Action="Warning" />
14+
<Rule Id="CA1061" Action="Warning" />
15+
<Rule Id="CA1063" Action="Warning" />
16+
<Rule Id="CA1065" Action="Warning" />
17+
<Rule Id="CA1301" Action="Warning" />
18+
<Rule Id="CA1400" Action="Warning" />
19+
<Rule Id="CA1401" Action="Warning" />
20+
<Rule Id="CA1403" Action="Warning" />
21+
<Rule Id="CA1404" Action="Warning" />
22+
<Rule Id="CA1405" Action="Warning" />
23+
<Rule Id="CA1410" Action="Warning" />
24+
<Rule Id="CA1415" Action="Warning" />
25+
<Rule Id="CA1821" Action="Warning" />
26+
<Rule Id="CA1900" Action="Warning" />
27+
<Rule Id="CA1901" Action="Warning" />
28+
<Rule Id="CA2002" Action="Warning" />
29+
<Rule Id="CA2100" Action="Warning" />
30+
<Rule Id="CA2101" Action="Warning" />
31+
<Rule Id="CA2108" Action="Warning" />
32+
<Rule Id="CA2111" Action="Warning" />
33+
<Rule Id="CA2112" Action="Warning" />
34+
<Rule Id="CA2114" Action="Warning" />
35+
<Rule Id="CA2116" Action="Warning" />
36+
<Rule Id="CA2117" Action="Warning" />
37+
<Rule Id="CA2122" Action="Warning" />
38+
<Rule Id="CA2123" Action="Warning" />
39+
<Rule Id="CA2124" Action="Warning" />
40+
<Rule Id="CA2126" Action="Warning" />
41+
<Rule Id="CA2131" Action="Warning" />
42+
<Rule Id="CA2132" Action="Warning" />
43+
<Rule Id="CA2133" Action="Warning" />
44+
<Rule Id="CA2134" Action="Warning" />
45+
<Rule Id="CA2137" Action="Warning" />
46+
<Rule Id="CA2138" Action="Warning" />
47+
<Rule Id="CA2140" Action="Warning" />
48+
<Rule Id="CA2141" Action="Warning" />
49+
<Rule Id="CA2146" Action="Warning" />
50+
<Rule Id="CA2147" Action="Warning" />
51+
<Rule Id="CA2149" Action="Warning" />
52+
<Rule Id="CA2200" Action="Warning" />
53+
<Rule Id="CA2202" Action="Warning" />
54+
<Rule Id="CA2207" Action="Warning" />
55+
<Rule Id="CA2212" Action="Warning" />
56+
<Rule Id="CA2213" Action="Warning" />
57+
<Rule Id="CA2214" Action="Warning" />
58+
<Rule Id="CA2216" Action="Warning" />
59+
<Rule Id="CA2220" Action="Warning" />
60+
<Rule Id="CA2229" Action="Warning" />
61+
<Rule Id="CA2231" Action="Warning" />
62+
<Rule Id="CA2232" Action="Warning" />
63+
<Rule Id="CA2235" Action="Warning" />
64+
<Rule Id="CA2236" Action="Warning" />
65+
<Rule Id="CA2237" Action="Error" />
66+
<Rule Id="CA2238" Action="Warning" />
67+
<Rule Id="CA2240" Action="Warning" />
68+
<Rule Id="CA2241" Action="Warning" />
69+
<Rule Id="CA2242" Action="Warning" />
70+
</Rules>
71+
<Rules AnalyzerId="Microsoft.CodeQuality.Analyzers" RuleNamespace="Microsoft.CodeQuality.Analyzers">
72+
<Rule Id="CA1031" Action="None" />
73+
<Rule Id="CA1034" Action="None" />
74+
<Rule Id="CA1051" Action="None" />
75+
<Rule Id="CA1805" Action="None" />
76+
</Rules>
77+
<Rules AnalyzerId="Microsoft.CodeQuality.CSharp.Analyzers" RuleNamespace="Microsoft.CodeQuality.CSharp.Analyzers">
78+
<Rule Id="CA1200" Action="None" />
79+
</Rules>
80+
<Rules AnalyzerId="Microsoft.NetCore.Analyzers" RuleNamespace="Microsoft.NetCore.Analyzers">
81+
<Rule Id="CA2000" Action="Error" />
82+
<Rule Id="CA2237" Action="Error" />
83+
</Rules>
84+
<Rules AnalyzerId="Microsoft.NetFramework.Analyzers" RuleNamespace="Microsoft.NetFramework.Analyzers">
85+
<Rule Id="CA3075" Action="Error" />
86+
</Rules>
87+
</RuleSet>

src/log4net/Appender/AdoNetAppender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ virtual protected string GetLogStatement(LoggingEvent logEvent)
617617
}
618618
else
619619
{
620-
StringWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
620+
using StringWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
621621
Layout.Format(writer, logEvent);
622622
return writer.ToString();
623623
}

src/log4net/Appender/FileAppender.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
using System;
2121
using System.IO;
22+
#if !NETCF && !NETSTANDARD1_3
23+
using System.Runtime.Serialization;
24+
#endif
2225
using System.Text;
2326
using System.Threading;
2427
using log4net.Util;
@@ -138,12 +141,29 @@ public class FileAppender : TextWriterAppender
138141
/// </summary>
139142
private sealed class LockingStream : Stream, IDisposable
140143
{
144+
#if !NETCR
145+
[Serializable]
146+
#endif
141147
public sealed class LockStateException : LogException
142148
{
143149
public LockStateException(string message)
144150
: base(message)
145151
{
146152
}
153+
154+
public LockStateException()
155+
{
156+
}
157+
158+
public LockStateException(string message, Exception innerException) : base(message, innerException)
159+
{
160+
}
161+
162+
#if !NETCR && !NETSTANDARD1_3
163+
private LockStateException(SerializationInfo info, StreamingContext context) : base(info, context)
164+
{
165+
}
166+
#endif
147167
}
148168

149169
private Stream m_realStream = null;
@@ -1409,7 +1429,10 @@ virtual protected void OpenFile(string fileName, bool append)
14091429
/// </remarks>
14101430
virtual protected void SetQWForFiles(Stream fileStream)
14111431
{
1412-
SetQWForFiles(new StreamWriter(fileStream, m_encoding));
1432+
#pragma warning disable CA2000 // Dispose objects before losing scope
1433+
StreamWriter writer = new StreamWriter(fileStream, m_encoding);
1434+
#pragma warning restore CA2000 // Dispose objects before losing scope
1435+
SetQWForFiles(writer);
14131436
}
14141437

14151438
/// <summary>

0 commit comments

Comments
 (0)