Skip to content

Commit b4f14a3

Browse files
committed
General Clean up and addition of Unit Test
- Added unit test for Log4net appender * Testing handing of Context Stack - Updated .gitignore - Changed Post build events to only run on Release * Updating the DLL folder only on Release will help to ensure you never accidently check in a debug build. - Updated Fody * Old version had issies with Roslyn and VS 2015 - Clean up extra copies of DLLs that were checked in
1 parent e1f1dec commit b4f14a3

File tree

24 files changed

+369
-129
lines changed

24 files changed

+369
-129
lines changed

Src/.gitignore

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,43 @@
44
# User-specific files
55
*.suo
66
*.user
7+
*.userosscache
78
*.sln.docstates
89

9-
# Build results
10+
# User-specific files (MonoDevelop/Xamarin Studio)
11+
*.userprefs
1012

13+
# Build results
1114
[Dd]ebug/
15+
[Dd]ebugPublic/
1216
[Rr]elease/
17+
[Rr]eleases/
1318
x64/
19+
x86/
1420
build/
21+
bld/
1522
[Bb]in/
1623
[Oo]bj/
1724

18-
# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
25+
# Visual Studo 2015 cache/options directory
26+
.vs/
1927

2028
# MSTest test Results
2129
[Tt]est[Rr]esult*/
2230
[Bb]uild[Ll]og.*
2331

32+
# NUNIT
33+
*.VisualState.xml
34+
TestResult.xml
35+
36+
# Build Results of an ATL Project
37+
[Dd]ebugPS/
38+
[Rr]eleasePS/
39+
dlldata.c
40+
2441
*_i.c
2542
*_p.c
43+
*_i.h
2644
*.ilk
2745
*.meta
2846
*.obj
@@ -42,9 +60,12 @@ build/
4260
*.vssscc
4361
.builds
4462
*.pidb
45-
*.log.*
63+
*.svclog
4664
*.scc
4765

66+
# Chutzpah Test files
67+
_Chutzpah*
68+
4869
# Visual C++ cache files
4970
ipch/
5071
*.aps
@@ -58,12 +79,19 @@ ipch/
5879
*.vsp
5980
*.vspx
6081

82+
# TFS 2012 Local Workspace
83+
$tf/
84+
6185
# Guidance Automation Toolkit
6286
*.gpState
6387

6488
# ReSharper is a .NET coding add-in
6589
_ReSharper*/
6690
*.[Rr]e[Ss]harper
91+
*.DotSettings.user
92+
93+
# JustCode is a .NET coding addin-in
94+
.JustCode
6795

6896
# TeamCity is a build add-in
6997
_TeamCity*
@@ -72,9 +100,16 @@ _TeamCity*
72100
*.dotCover
73101

74102
# NCrunch
75-
*.ncrunch*
103+
_NCrunch_*
76104
.*crunch*.local.xml
77105

106+
# MightyMoose
107+
*.mm.*
108+
AutoTest.Net/
109+
110+
# Web workbench (sass)
111+
.sass-cache/
112+
78113
# Installshield output folder
79114
[Ee]xpress/
80115

@@ -92,51 +127,67 @@ DocProject/Help/html
92127
publish/
93128

94129
# Publish Web Output
95-
*.Publish.xml
96-
97-
# NuGet Packages Directory
98-
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
99-
#packages/
130+
*.[Pp]ublish.xml
131+
*.azurePubxml
132+
# TODO: Comment the next line if you want to checkin your web deploy settings
133+
# but database connection strings (with potential passwords) will be unencrypted
134+
*.pubxml
135+
*.publishproj
136+
137+
# NuGet Packages
138+
*.nupkg
139+
# The packages folder can be ignored because of Package Restore
140+
packages/
141+
# except build/, which is used as an MSBuild target.
142+
!packages/build/
143+
# Uncomment if necessary however generally it will be regenerated when needed
144+
#!**/packages/repositories.config
100145

101146
# Windows Azure Build Output
102-
csx
147+
csx/
103148
*.build.csdef
104149

105150
# Windows Store app package directory
106151
AppPackages/
107152

108153
# Others
109-
sql/
110-
*.Cache
154+
*.[Cc]ache
111155
ClientBin/
112156
[Ss]tyle[Cc]op.*
113157
~$*
114158
*~
115159
*.dbmdl
116-
*.[Pp]ublish.xml
160+
*.dbproj.schemaview
117161
*.pfx
118162
*.publishsettings
163+
node_modules/
164+
bower_components/
119165

120166
# RIA/Silverlight projects
121167
Generated_Code/
122168

123-
# Backup & report files from converting an old project file to a newer
124-
# Visual Studio version. Backup files are not needed, because we have git ;-)
169+
# Backup & report files from converting an old project file
170+
# to a newer Visual Studio version. Backup files are not needed,
171+
# because we have git ;-)
125172
_UpgradeReport_Files/
126173
Backup*/
127174
UpgradeLog*.XML
128175
UpgradeLog*.htm
129176

130177
# SQL Server files
131-
App_Data/*.mdf
132-
App_Data/*.ldf
178+
*.mdf
179+
*.ldf
133180

181+
# Business Intelligence projects
182+
*.rdl.data
183+
*.bim.layout
184+
*.bim_*.settings
134185

135-
#LightSwitch generated files
136-
GeneratedArtifacts/
137-
_Pvt_Extensions/
138-
ModelManifest.xml
186+
# Microsoft Fakes
187+
FakesAssemblies/
139188

189+
# Node.js Tools for Visual Studio
190+
.ntvs_analysis.dat
140191
# =========================
141192
# Windows detritus
142193
# =========================
@@ -161,3 +212,4 @@ $RECYCLE.BIN/
161212
# Allow files
162213
!*/packages/*
163214
!/ThirdParty/*
215+
-12.5 KB
Binary file not shown.
-11 KB
Binary file not shown.

Src/StackifyLib.ELMAH/StackifyLib.ELMAH.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
</ItemGroup>
6262
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6363
<PropertyGroup>
64-
<PostBuildEvent>cmd /C Copy "$(TargetPath)" "..\..\..\..\dlls\StackifyLib.ELMAH\"</PostBuildEvent>
64+
<PostBuildEvent>if $(ConfigurationName) == Release cmd /C Copy "$(TargetPath)" "..\..\..\..\dlls\$(ProjectName)\"</PostBuildEvent>
6565
</PropertyGroup>
6666
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
6767
Other similar extension points exist, see Microsoft.Common.targets.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("StackifyLib.log4net.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("StackifyLib.log4net.Tests")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("18f96933-468e-4104-961e-0c68a5ef2b29")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using log4net;
7+
using log4net.Appender;
8+
using log4net.Core;
9+
using log4net.Layout;
10+
using log4net.Repository.Hierarchy;
11+
using Newtonsoft.Json;
12+
using Newtonsoft.Json.Linq;
13+
using NUnit.Framework;
14+
using StackifyLib.Internal.Logs;
15+
using StackifyLib.Models;
16+
using StackifyLib.Utils;
17+
18+
namespace StackifyLib.log4net.Tests
19+
{
20+
[TestFixture]
21+
public class StackifyAppenderTest
22+
{
23+
private MockLogClient _mockLogClient;
24+
private StackifyAppender _appender;
25+
26+
[SetUp]
27+
public void Init()
28+
{
29+
_mockLogClient = new MockLogClient();
30+
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
31+
32+
PatternLayout patternLayout = new PatternLayout();
33+
patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
34+
patternLayout.ActivateOptions();
35+
36+
RollingFileAppender roller = new RollingFileAppender();
37+
roller.AppendToFile = false;
38+
roller.File = @"Logs\EventLog.txt";
39+
roller.Layout = patternLayout;
40+
roller.MaxSizeRollBackups = 5;
41+
roller.MaximumFileSize = "1GB";
42+
roller.RollingStyle = RollingFileAppender.RollingMode.Size;
43+
roller.StaticLogFileName = true;
44+
roller.ActivateOptions();
45+
hierarchy.Root.AddAppender(roller);
46+
47+
_appender = new StackifyAppender { CreateLogClient = (s, s1) => _mockLogClient, threadContextKeys = "TestThreadContext", logicalThreadContextKeys = "TestLogicalThreadContext" };
48+
_appender.ActivateOptions();
49+
hierarchy.Root.AddAppender(_appender);
50+
51+
hierarchy.Root.Level = Level.Info;
52+
hierarchy.Configured = true;
53+
}
54+
55+
[Test]
56+
public void ShouldIncludeContextObjects_WhenUsingLog4NetContextStacks()
57+
{
58+
LogMsg result = null;
59+
_mockLogClient.OnQueueMessage = m => result = m;
60+
var logger = LogManager.GetLogger("Test");
61+
using (LogicalThreadContext.Stacks["TestLogicalThreadContext"].Push("Logical Test Value"))
62+
using (ThreadContext.Stacks["TestThreadContext"].Push("Thread Test Value"))
63+
{
64+
logger.Info("Test Message");
65+
}
66+
67+
Console.WriteLine("Actual Result:");
68+
Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
69+
Console.WriteLine();
70+
71+
Assert.IsNotNull(result, "No Message was queued");
72+
Assert.IsNotNull(result.data, "Data was not set on result");
73+
74+
// Data is JSON, so we are going to Deserialize it so we can take a deeper look.
75+
dynamic dataObj = JsonConvert.DeserializeObject(result.data);
76+
77+
Assert.AreEqual("Thread Test Value", dataObj.context.testthreadcontext.Value, "TestThreadContext didn't match expected value.");
78+
Assert.AreEqual("Logical Test Value", dataObj.context.testlogicalthreadcontext.Value, "TestLogicalThreadContext didn't match expected value");
79+
}
80+
}
81+
82+
public class MockLogClient : ILogClient
83+
{
84+
public Action<LogMsg> OnQueueMessage;
85+
86+
public bool CanQueue()
87+
{
88+
return true;
89+
}
90+
91+
public bool CanSend()
92+
{
93+
return true;
94+
}
95+
96+
public bool CanUpload()
97+
{
98+
return true;
99+
}
100+
101+
public void Close()
102+
{
103+
}
104+
105+
public bool ErrorShouldBeSent(StackifyError error)
106+
{
107+
return true;
108+
}
109+
110+
public AppIdentityInfo GetIdentity()
111+
{
112+
throw new NotImplementedException();
113+
}
114+
115+
public bool IsAuthorized()
116+
{
117+
return true;
118+
}
119+
120+
public void PauseUpload(bool isPaused)
121+
{
122+
}
123+
124+
public void QueueMessage(LogMsg msg)
125+
{
126+
var action = OnQueueMessage;
127+
action?.Invoke(msg);
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)