├── .gitattributes ├── .gitignore ├── .nuget ├── NuGet.Config ├── NuGet.exe └── NuGet.targets ├── README.md ├── Settings.StyleCop ├── UnityLog4NetExtension.Specs ├── CreationStackReporter │ ├── ClassWithCtor_SimpleDependency_UnityObjectCreationStack.cs │ ├── ClassWithCtor_UnityObjectCreationStack.cs │ ├── CreationStackTrackerExtensionSpecs.cs │ ├── IClassWithUnityObjectCreationStack.cs │ ├── SimpleClass.cs │ └── ThreeLevelHeirarchyClass.cs ├── Log4Net │ ├── ClassWithSingleILogDependency.cs │ ├── Log4NetExtensionSpecs.cs │ ├── SimpleClass.cs │ └── ThreeLevelHeirarchyClass.cs ├── Properties │ └── AssemblyInfo.cs ├── Settings.StyleCop ├── UnityLog4NetExtension.Specs.csproj ├── UnityLog4NetExtension.Specs.ncrunchproject └── packages.config ├── UnityLog4NetExtension.ncrunchsolution ├── UnityLog4NetExtension.sln ├── UnityLog4NetExtension.sln.DotSettings ├── UnityLog4NetExtension ├── CreationStackReporter │ ├── CreationStackReporterExtension.cs │ └── CreationStackReporterStrategy.cs ├── CreationStackTracker │ ├── CreationStackTrackerExtension.cs │ ├── CreationStackTrackerPolicy.cs │ ├── CreationStackTrackerStrategy.cs │ ├── ICreationStackTrackerPolicy.cs │ ├── LoggingBuilderStrategy.cs │ └── UnityObjectCreationStack.cs ├── Log4Net │ ├── Log4NetExtension.cs │ └── Log4NetStrategy.cs ├── PeekableStack.cs ├── Properties │ └── AssemblyInfo.cs ├── UnityLog4NetExtension.csproj ├── UnityLog4NetExtension.ncrunchproject ├── UnityLog4NetExtension.nuspec ├── createNugetPackage.cmd ├── keypair.snk └── packages.config ├── keypair.snk └── license.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | [Dd]ebug/ 46 | [Rr]elease/ 47 | *_i.c 48 | *_p.c 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.vspscc 63 | .builds 64 | *.dotCover 65 | *.nupkg 66 | 67 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 68 | packages/ 69 | 70 | # Visual C++ cache files 71 | ipch/ 72 | *.aps 73 | *.ncb 74 | *.opensdf 75 | *.sdf 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | 81 | # ReSharper is a .NET coding add-in 82 | _ReSharper* 83 | 84 | # Installshield output folder 85 | [Ee]xpress 86 | 87 | # DocProject is a documentation generator add-in 88 | DocProject/buildhelp/ 89 | DocProject/Help/*.HxT 90 | DocProject/Help/*.HxC 91 | DocProject/Help/*.hhc 92 | DocProject/Help/*.hhk 93 | DocProject/Help/*.hhp 94 | DocProject/Help/Html2 95 | DocProject/Help/html 96 | 97 | # Click-Once directory 98 | publish 99 | 100 | # Others 101 | [Bb]in 102 | [Oo]bj 103 | sql 104 | TestResults 105 | *.Cache 106 | ClientBin 107 | stylecop.* 108 | ~$* 109 | *.dbmdl 110 | Generated_Code #added for RIA/Silverlight projects 111 | 112 | # Backup & report files from converting an old project file to a newer 113 | # Visual Studio version. Backup files are not needed, because we have git ;-) 114 | _UpgradeReport_Files/ 115 | Backup*/ 116 | UpgradeLog*.XML 117 | 118 | 119 | 120 | ############ 121 | ## Windows 122 | ############ 123 | 124 | # Windows image file caches 125 | Thumbs.db 126 | 127 | # Folder config file 128 | Desktop.ini 129 | 130 | 131 | ############# 132 | ## Python 133 | ############# 134 | 135 | *.py[co] 136 | 137 | # Packages 138 | *.egg 139 | *.egg-info 140 | dist 141 | build 142 | eggs 143 | parts 144 | bin 145 | var 146 | sdist 147 | develop-eggs 148 | .installed.cfg 149 | 150 | # Installer logs 151 | pip-log.txt 152 | 153 | # Unit test / coverage reports 154 | .coverage 155 | .tox 156 | 157 | #Translations 158 | *.mo 159 | 160 | #Mr Developer 161 | .mr.developer.cfg 162 | 163 | # Mac crap 164 | .DS_Store 165 | *.ncrunch* 166 | -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roblevine/UnityLog4NetExtension/7a39c0f417d018c7af6f417d55fcb19bffd1810b/.nuget/NuGet.exe -------------------------------------------------------------------------------- /.nuget/NuGet.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildProjectDirectory)\..\ 5 | 6 | 7 | false 8 | 9 | 10 | false 11 | 12 | 13 | true 14 | 15 | 16 | false 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) 31 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) 32 | $([System.IO.Path]::Combine($(SolutionDir), "packages")) 33 | 34 | 35 | 36 | 37 | $(SolutionDir).nuget 38 | packages.config 39 | $(SolutionDir)packages 40 | 41 | 42 | 43 | 44 | $(NuGetToolsPath)\nuget.exe 45 | @(PackageSource) 46 | 47 | "$(NuGetExePath)" 48 | mono --runtime=v4.0.30319 $(NuGetExePath) 49 | 50 | $(TargetDir.Trim('\\')) 51 | 52 | -RequireConsent 53 | 54 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -o "$(PackagesDir)" 55 | $(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols 56 | 57 | 58 | 59 | RestorePackages; 60 | $(ResolveReferencesDependsOn); 61 | 62 | 63 | 64 | 65 | $(BuildDependsOn); 66 | BuildPackage; 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 89 | 90 | 93 | 94 | 95 | 96 | 98 | 99 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Note: this extension is retired for Unity 5 and higher. Please use the official [Unity Log4Net extension](https://github.com/unitycontainer/log4net) instead.** 2 | 3 | ***Note on Unity versions and branches*** 4 | 5 | The `unity-pre-4` branch contains the version of this extension for use with with Unity versions prior to 4. 6 | 7 | The `unity-4` branch contains the version of this extension for use with with Unity version 4 and higher. 8 | 9 | **UnityLoggingExtensions** 10 | 11 | This library was born out of a desire to have a simple extension to Unity that would enable log4net `ILog` dependencies to be injected into consuming classes, with the ILog instance being the configured as the correct logger for the consuming class. 12 | 13 | A fairly standard pattern for declaring a log4net logger in a class is: 14 | 15 | public class MyClass 16 | { 17 | private static readonly ILog logger = LogManager.GetLogger(typeof(MyClass)); 18 | } 19 | 20 | I want to acheive a similarly configured logger, but have it passed in at construction time: 21 | 22 | public class MyClass 23 | { 24 | private readonly ILog logger; 25 | 26 | public MyClass(ILog logger) 27 | { 28 | this.logger = logger; 29 | } 30 | } 31 | 32 | There has been some discussion online as to how best to acheive this: 33 | 34 | http://stackoverflow.com/questions/6846342/how-to-inject-log4net-ilog-implementations-using-unity-2-0 35 | http://davidkeaveny.blogspot.co.uk/2011/03/unity-and-log4net.html 36 | http://blog.baltrinic.com/software-development/dotnet/log4net-integration-with-unity-ioc-container 37 | 38 | The solutions discussed and presented in these articles (in particular the last one), inspired me to write this extension as an improvement over Kenneth Baltrinic's documented solution. Although his suggested solution works - it involves some stack walking to identify the `Type` of the logger to create. I felt that this should be available from within Unity itself without the need to resort to handling `StackTrace`/`StackFrame` classes. 39 | 40 | In order to acheive the desired end result, three extensions have been written. Two are directly related to this, and one to help with testing: 41 | 42 | **CreationStackTrackerExtension** 43 | This extension is responsible for mainting a stack of the type creation hierarchy. At the creation of any given type via unity, the stack provided by this extension will show the parent class, grandparent, etc. 44 | 45 | **Log4NetExtension** 46 | Relying on the extension above, this intercepts any request for an `ILog` instance and creates an `ILog` instance by calling `LogManager.GetLogger(Type t)` using the type of the parent class (ie the class the logger is being injected into) 47 | 48 | This can be registered as follows: 49 | 50 | var container = new UnityContainer(); 51 | container.AddNewExtension(); 52 | 53 | Once registered, any `ILog` dependencies will resolve to a log4net logger with a type name matching the type it will be injected into. 54 | 55 | **CreationStackReporterExtension** 56 | This is used in the unit tests and relies on the _CreationStackTrackerExtension_ extension above. It introduces the `UnityObjectCreationStack` type which, when injected into a constructor, contains the object creation stack. This stack can then be used to assert that the extension is behaving correctly. 57 | 58 | var container = new UnityContainer(); 59 | container.AddNewExtension(); 60 | 61 | Once registered, any `UnityObjectCreationStack` dependencies will resolve to an instance that contains the type creation stack 62 | 63 | public class MyClass 64 | { 65 | public MyClass(UnityObjectCreationStack unityObjectCreationStack) 66 | { 67 | 68 | } 69 | } 70 | 71 | See http://blog.roblevine.co.uk/net/using-log4net-with-unity/ for more info. 72 | 73 | NOTE: This is now available as a NuGet package: 74 | https://www.nuget.org/packages/UnityLog4NetExtension/ 75 | 76 | NOTE: Tests are written using Machine Specifications [https://github.com/machine/machine.specifications]. If you are using ReSharper as your test runner, you'll need to run the following batch file to get MSpec to work with the ReSharper runner: 77 | 78 | `UnityLoggingExtensions\packages\Machine.Specifications.0.5.10\tools\InstallResharperRunner.x.x.bat` 79 | -------------------------------------------------------------------------------- /Settings.StyleCop: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | False 8 | 9 | 10 | 11 | 12 | False 13 | 14 | 15 | 16 | 17 | False 18 | 19 | 20 | 21 | 22 | False 23 | 24 | 25 | 26 | 27 | False 28 | 29 | 30 | 31 | 32 | False 33 | 34 | 35 | 36 | 37 | False 38 | 39 | 40 | 41 | 42 | False 43 | 44 | 45 | 46 | 47 | False 48 | 49 | 50 | 51 | 52 | False 53 | 54 | 55 | 56 | 57 | False 58 | 59 | 60 | 61 | 62 | False 63 | 64 | 65 | 66 | 67 | False 68 | 69 | 70 | 71 | 72 | False 73 | 74 | 75 | 76 | 77 | False 78 | 79 | 80 | 81 | 82 | False 83 | 84 | 85 | 86 | 87 | False 88 | 89 | 90 | 91 | 92 | False 93 | 94 | 95 | 96 | 97 | False 98 | 99 | 100 | 101 | 102 | False 103 | 104 | 105 | 106 | 107 | False 108 | 109 | 110 | 111 | 112 | False 113 | 114 | 115 | 116 | 117 | False 118 | 119 | 120 | 121 | 122 | False 123 | 124 | 125 | 126 | 127 | False 128 | 129 | 130 | 131 | 132 | False 133 | 134 | 135 | 136 | 137 | False 138 | 139 | 140 | 141 | 142 | False 143 | 144 | 145 | 146 | 147 | False 148 | 149 | 150 | 151 | 152 | False 153 | 154 | 155 | 156 | 157 | False 158 | 159 | 160 | 161 | 162 | False 163 | 164 | 165 | 166 | 167 | False 168 | 169 | 170 | 171 | 172 | False 173 | 174 | 175 | 176 | 177 | False 178 | 179 | 180 | 181 | 182 | False 183 | 184 | 185 | 186 | 187 | False 188 | 189 | 190 | 191 | 192 | False 193 | 194 | 195 | 196 | 197 | False 198 | 199 | 200 | 201 | 202 | False 203 | 204 | 205 | 206 | 207 | False 208 | 209 | 210 | 211 | 212 | False 213 | 214 | 215 | 216 | 217 | 218 | 219 | -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/CreationStackReporter/ClassWithCtor_SimpleDependency_UnityObjectCreationStack.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using UnityLog4NetExtension.CreationStackTracker; 34 | 35 | namespace UnityLog4NetExtension.Specs.CreationStackReporter 36 | { 37 | public class ClassWithCtor_SimpleDependency_UnityObjectCreationStack : IClassWithUnityObjectCreationStack 38 | { 39 | public ClassWithCtor_SimpleDependency_UnityObjectCreationStack(SimpleClass simpleClass, 40 | UnityObjectCreationStack unityObjectCreationStack) 41 | { 42 | UnityObjectCreationStack = unityObjectCreationStack; 43 | } 44 | 45 | public UnityObjectCreationStack UnityObjectCreationStack { get; set; } 46 | } 47 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/CreationStackReporter/ClassWithCtor_UnityObjectCreationStack.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using UnityLog4NetExtension.CreationStackTracker; 34 | 35 | namespace UnityLog4NetExtension.Specs.CreationStackReporter 36 | { 37 | public class ClassWithCtor_UnityObjectCreationStack : IClassWithUnityObjectCreationStack 38 | { 39 | public ClassWithCtor_UnityObjectCreationStack(UnityObjectCreationStack unityObjectCreationStack) 40 | { 41 | UnityObjectCreationStack = unityObjectCreationStack; 42 | } 43 | 44 | public UnityObjectCreationStack UnityObjectCreationStack { get; set; } 45 | } 46 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/CreationStackReporter/CreationStackTrackerExtensionSpecs.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using Machine.Specifications; 34 | using Microsoft.Practices.Unity; 35 | using UnityLog4NetExtension.CreationStackReporter; 36 | using UnityLog4NetExtension.CreationStackTracker; 37 | 38 | namespace UnityLog4NetExtension.Specs.CreationStackReporter 39 | { 40 | [Subject(typeof (CreationStackReporterExtension))] 41 | public class when_a_class_with_a_single_ctor_param_of_UnityObjectCreationStack_is_constructed : CreationStackReporterSpecsContext 42 | { 43 | Establish establish = () => unityContainer.RegisterType(); 44 | 45 | Because because = () => classRequiringInterceptedDependency = unityContainer.Resolve(); 46 | 47 | It stack_should_not_be_null = () => classRequiringInterceptedDependency.UnityObjectCreationStack.ShouldNotBeNull(); 48 | 49 | It then_current_item_on_call_stack_should_be_the_UnityObjectCreationStack_class_being_created = () => 50 | classRequiringInterceptedDependency.UnityObjectCreationStack.Peek(0) 51 | .FullName.ShouldEqual(typeof (UnityObjectCreationStack).FullName); 52 | 53 | It then_previous_item_on_call_stack_should_be_the_parent_class_requiring_this_dependency = () => 54 | classRequiringInterceptedDependency.UnityObjectCreationStack.Peek(1) 55 | .FullName.ShouldEqual(typeof (ClassWithCtor_UnityObjectCreationStack).FullName); 56 | } 57 | 58 | [Subject(typeof (CreationStackReporterExtension))] 59 | public class when_a_class_with_a_two_ctor_param_of_string_and_UnityObjectCreationStack_is_constructed : CreationStackReporterSpecsContext 60 | { 61 | Establish establish = () => unityContainer.RegisterType(); 62 | 63 | Because because = () => classRequiringInterceptedDependency = unityContainer.Resolve(); 64 | 65 | It then_current_item_on_call_stack_should_be_the_UnityObjectCreationStack_class_being_created = () => 66 | classRequiringInterceptedDependency.UnityObjectCreationStack.Peek(0) 67 | .FullName.ShouldEqual(typeof (UnityObjectCreationStack).FullName); 68 | 69 | It then_previous_item_on_call_stack_should_be_the_parent_class_requiring_this_dependency = () => 70 | classRequiringInterceptedDependency.UnityObjectCreationStack.Peek(1) 71 | .FullName.ShouldEqual(typeof (ClassWithCtor_SimpleDependency_UnityObjectCreationStack).FullName); 72 | } 73 | 74 | public class CreationStackReporterSpecsContext 75 | { 76 | protected static UnityContainer unityContainer; 77 | 78 | protected static CreationStackTrackerExtension subject; 79 | 80 | protected static IClassWithUnityObjectCreationStack classRequiringInterceptedDependency; 81 | 82 | Establish establish = () => 83 | { 84 | unityContainer = new UnityContainer(); 85 | unityContainer.AddNewExtension(); 86 | }; 87 | } 88 | 89 | [Subject(typeof (CreationStackReporterExtension))] 90 | public class when_a_class_heirachy_is_created_with_monitoring_stack_dependency_at_depth_of_third_level 91 | { 92 | private static UnityContainer unityContainer; 93 | private static TopLevel topLevelClass; 94 | private static ThirdLevel thirdLevelClass; 95 | 96 | Establish establish = () => 97 | { 98 | unityContainer = new UnityContainer(); 99 | unityContainer.AddNewExtension(); 100 | }; 101 | 102 | Because because = () => 103 | { 104 | topLevelClass = unityContainer.Resolve(); 105 | thirdLevelClass = topLevelClass.SecondLevel.ThirdLevel; 106 | }; 107 | 108 | It dependency_being_created_sees_its_immediate_parent_as_third_level_class = 109 | () => thirdLevelClass.UnityObjectCreationStack.Peek(1).FullName.ShouldEqual(typeof (ThirdLevel).FullName); 110 | 111 | It dependency_being_created_sees_the_top_of_the_creation_stack_as_itself = 112 | () => 113 | thirdLevelClass.UnityObjectCreationStack.Peek(0) 114 | .FullName.ShouldEqual(typeof (UnityObjectCreationStack).FullName); 115 | 116 | It third_level_class_sees_its_grandparent_as_top_level_class = 117 | () => thirdLevelClass.UnityObjectCreationStack.Peek(3).FullName.ShouldEqual(typeof (TopLevel).FullName); 118 | 119 | It third_level_class_sees_its_immediate_parent_as_second_level_class = 120 | () => thirdLevelClass.UnityObjectCreationStack.Peek(2).FullName.ShouldEqual(typeof (SecondLevel).FullName); 121 | } 122 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/CreationStackReporter/IClassWithUnityObjectCreationStack.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using UnityLog4NetExtension.CreationStackTracker; 34 | 35 | namespace UnityLog4NetExtension.Specs.CreationStackReporter 36 | { 37 | public interface IClassWithUnityObjectCreationStack 38 | { 39 | UnityObjectCreationStack UnityObjectCreationStack { get; set; } 40 | } 41 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/CreationStackReporter/SimpleClass.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | namespace UnityLog4NetExtension.Specs.CreationStackReporter 34 | { 35 | public class SimpleClass 36 | { 37 | } 38 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/CreationStackReporter/ThreeLevelHeirarchyClass.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using System; 34 | using UnityLog4NetExtension.CreationStackTracker; 35 | 36 | namespace UnityLog4NetExtension.Specs.CreationStackReporter 37 | { 38 | public class TopLevel 39 | { 40 | private readonly SecondLevel secondLevel; 41 | 42 | public TopLevel(SimpleClass c1, SecondLevel secondLevel, SimpleClass c3) 43 | { 44 | this.secondLevel = secondLevel; 45 | } 46 | 47 | public SecondLevel SecondLevel 48 | { 49 | get { return secondLevel; } 50 | } 51 | } 52 | 53 | public class SecondLevel 54 | { 55 | private readonly ThirdLevel thirdLevel; 56 | 57 | public SecondLevel(SimpleClass c1, ThirdLevel thirdLevel, SimpleClass c3) 58 | { 59 | this.thirdLevel = thirdLevel; 60 | } 61 | 62 | public ThirdLevel ThirdLevel 63 | { 64 | get { return thirdLevel; } 65 | } 66 | } 67 | 68 | public class ThirdLevel 69 | { 70 | private readonly PeekableStack unityObjectCreationStack; 71 | 72 | public ThirdLevel(SimpleClass c1, UnityObjectCreationStack unityObjectCreationStack, SimpleClass c3) 73 | { 74 | this.unityObjectCreationStack = new PeekableStack(unityObjectCreationStack.Items); 75 | } 76 | 77 | public PeekableStack UnityObjectCreationStack 78 | { 79 | get { return unityObjectCreationStack; } 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/Log4Net/ClassWithSingleILogDependency.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using log4net; 34 | 35 | namespace UnityLog4NetExtension.Specs.Log4Net 36 | { 37 | public class ClassWithSingleILogDependency 38 | { 39 | private readonly ILog logger; 40 | 41 | public ClassWithSingleILogDependency(ILog logger) 42 | { 43 | this.logger = logger; 44 | } 45 | 46 | public ILog Logger 47 | { 48 | get { return logger; } 49 | } 50 | } 51 | 52 | public class ClassWithTwoDependencies_SimpleClass_and_ILog 53 | { 54 | private readonly ILog logger; 55 | 56 | public ClassWithTwoDependencies_SimpleClass_and_ILog(SimpleClass simpleClass, ILog logger) 57 | { 58 | this.logger = logger; 59 | } 60 | 61 | public ILog Logger 62 | { 63 | get { return logger; } 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/Log4Net/Log4NetExtensionSpecs.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using Machine.Specifications; 34 | using Microsoft.Practices.Unity; 35 | using UnityLog4NetExtension.Log4Net; 36 | 37 | namespace UnityLog4NetExtension.Specs.Log4Net 38 | { 39 | [Subject(typeof (Log4NetExtension))] 40 | public class when_a_class_taking_a_single_ILog_dependency_is_created_via_unity 41 | { 42 | private static IUnityContainer container; 43 | 44 | private static ClassWithSingleILogDependency classWithDependency; 45 | 46 | Establish establish = () => 47 | { 48 | container = new UnityContainer(); 49 | container.AddNewExtension(); 50 | }; 51 | 52 | Because because = () => classWithDependency = container.Resolve(); 53 | 54 | It the_injected_logger_has_a_name_corresponding_to_the_type_it_is_being_injected_into = () => classWithDependency.Logger.Logger.Name.ShouldEqual(typeof (ClassWithSingleILogDependency).FullName); 55 | 56 | It the_injected_logger_is_not_null = () => classWithDependency.Logger.ShouldNotBeNull(); 57 | } 58 | 59 | [Subject(typeof (Log4NetExtension))] 60 | public class when_a_class_taking_SimpleClass_and_ILog_as_dependencies_is_created_via_unity 61 | { 62 | private static IUnityContainer container; 63 | 64 | private static ClassWithTwoDependencies_SimpleClass_and_ILog classWithDependency; 65 | 66 | Establish establish = () => 67 | { 68 | container = new UnityContainer(); 69 | container.AddNewExtension(); 70 | }; 71 | 72 | Because because = () => classWithDependency = container.Resolve(); 73 | 74 | It the_injected_logger_has_a_name_corresponding_to_the_type_it_is_being_injected_into = 75 | () => 76 | classWithDependency.Logger.Logger.Name.ShouldEqual( 77 | typeof (ClassWithTwoDependencies_SimpleClass_and_ILog).FullName); 78 | 79 | It the_injected_logger_is_not_null = () => classWithDependency.Logger.ShouldNotBeNull(); 80 | } 81 | 82 | [Subject(typeof (Log4NetExtension))] 83 | public class when_a_three_level_class_heirarchy_is_created_with_the_third_level_class_taking_an_ILog_as_a_dependency 84 | { 85 | private static IUnityContainer container; 86 | 87 | private static TopLevel classWithDependency; 88 | 89 | Establish establish = () => 90 | { 91 | container = new UnityContainer(); 92 | container.AddNewExtension(); 93 | }; 94 | 95 | Because because = () => classWithDependency = container.Resolve(); 96 | 97 | It the_injected_logger_has_a_name_corresponding_to_the_type_it_is_being_injected_into = () => classWithDependency.SecondLevel.ThirdLevel.Logger.Logger.Name.ShouldEqual(typeof (ThirdLevel).FullName); 98 | 99 | It the_injected_logger_is_not_null = () => classWithDependency.SecondLevel.ThirdLevel.Logger.ShouldNotBeNull(); 100 | } 101 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/Log4Net/SimpleClass.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | namespace UnityLog4NetExtension.Specs.Log4Net 34 | { 35 | public class SimpleClass 36 | { 37 | } 38 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/Log4Net/ThreeLevelHeirarchyClass.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using log4net; 34 | 35 | namespace UnityLog4NetExtension.Specs.Log4Net 36 | { 37 | public class TopLevel 38 | { 39 | private readonly SecondLevel secondLevel; 40 | 41 | public TopLevel(SimpleClass c1, SecondLevel secondLevel, SimpleClass c3) 42 | { 43 | this.secondLevel = secondLevel; 44 | } 45 | 46 | public SecondLevel SecondLevel 47 | { 48 | get { return secondLevel; } 49 | } 50 | } 51 | 52 | public class SecondLevel 53 | { 54 | private readonly ThirdLevel thirdLevel; 55 | 56 | public SecondLevel(SimpleClass c1, ThirdLevel thirdLevel, SimpleClass c3) 57 | { 58 | this.thirdLevel = thirdLevel; 59 | } 60 | 61 | public ThirdLevel ThirdLevel 62 | { 63 | get { return thirdLevel; } 64 | } 65 | } 66 | 67 | public class ThirdLevel 68 | { 69 | private readonly ILog logger; 70 | 71 | public ThirdLevel(SimpleClass c1, ILog logger, SimpleClass c3) 72 | { 73 | this.logger = logger; 74 | } 75 | 76 | public ILog Logger 77 | { 78 | get { return logger; } 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using System.Reflection; 34 | using System.Runtime.InteropServices; 35 | 36 | // General Information about an assembly is controlled through the following 37 | // set of attributes. Change these attribute values to modify the information 38 | // associated with an assembly. 39 | 40 | [assembly: AssemblyTitle("UnityLog4NetExtension.Specs")] 41 | [assembly: AssemblyDescription("")] 42 | [assembly: AssemblyConfiguration("")] 43 | [assembly: AssemblyCompany("INEX Solutions Ltd")] 44 | [assembly: AssemblyProduct("UnityLog4NetExtension.Specs")] 45 | [assembly: AssemblyCopyright("Copyright © INEX Solutions Ltd 2012")] 46 | [assembly: AssemblyTrademark("")] 47 | [assembly: AssemblyCulture("")] 48 | 49 | // Setting ComVisible to false makes the types in this assembly not visible 50 | // to COM components. If you need to access a type in this assembly from 51 | // COM, set the ComVisible attribute to true on that type. 52 | 53 | [assembly: ComVisible(false)] 54 | 55 | // The following GUID is for the ID of the typelib if this project is exposed to COM 56 | 57 | [assembly: Guid("4d237f3f-ba41-4fb3-b9f4-a1883256f661")] 58 | 59 | // Version information for an assembly consists of the following four values: 60 | // 61 | // Major Version 62 | // Minor Version 63 | // Build Number 64 | // Revision 65 | // 66 | // You can specify all the values or you can default the Build and Revision Numbers 67 | // by using the '*' as shown below: 68 | // [assembly: AssemblyVersion("1.0.*")] 69 | 70 | [assembly: AssemblyVersion("1.1.0.0")] 71 | [assembly: AssemblyFileVersion("1.1.0.0")] -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/Settings.StyleCop: -------------------------------------------------------------------------------- 1 | 2 | 3 | ..\Settings.StyleCop 4 | Linked 5 | 6 | 7 | 8 | 9 | 10 | 11 | False 12 | 13 | 14 | 15 | 16 | False 17 | 18 | 19 | 20 | 21 | False 22 | 23 | 24 | 25 | 26 | False 27 | 28 | 29 | 30 | 31 | False 32 | 33 | 34 | 35 | 36 | False 37 | 38 | 39 | 40 | 41 | False 42 | 43 | 44 | 45 | 46 | False 47 | 48 | 49 | 50 | 51 | False 52 | 53 | 54 | 55 | 56 | False 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | False 67 | 68 | 69 | 70 | 71 | False 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | False 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | False 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | False 102 | 103 | 104 | 105 | 106 | False 107 | 108 | 109 | 110 | 111 | False 112 | 113 | 114 | 115 | 116 | False 117 | 118 | 119 | 120 | 121 | False 122 | 123 | 124 | 125 | 126 | False 127 | 128 | 129 | 130 | 131 | False 132 | 133 | 134 | 135 | 136 | False 137 | 138 | 139 | 140 | 141 | False 142 | 143 | 144 | 145 | 146 | False 147 | 148 | 149 | 150 | 151 | False 152 | 153 | 154 | 155 | 156 | False 157 | 158 | 159 | 160 | 161 | False 162 | 163 | 164 | 165 | 166 | False 167 | 168 | 169 | 170 | 171 | False 172 | 173 | 174 | 175 | 176 | False 177 | 178 | 179 | 180 | 181 | False 182 | 183 | 184 | 185 | 186 | False 187 | 188 | 189 | 190 | 191 | False 192 | 193 | 194 | 195 | 196 | 197 | 198 | -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/UnityLog4NetExtension.Specs.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {83BC3A6D-9DB3-4BFA-817A-9BB4128BD357} 9 | Library 10 | Properties 11 | UnityLog4NetExtension.Specs 12 | UnityLog4NetExtension.Specs 13 | v4.0 14 | 512 15 | ..\ 16 | true 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | false 27 | 28 | 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | false 36 | 37 | 38 | 39 | False 40 | ..\packages\log4net.2.0.3\lib\net40-full\log4net.dll 41 | 42 | 43 | ..\packages\Machine.Specifications.0.9.3\lib\net40\Machine.Specifications.dll 44 | True 45 | 46 | 47 | ..\packages\Machine.Specifications.0.9.3\lib\net40\Machine.Specifications.Clr4.dll 48 | True 49 | 50 | 51 | ..\packages\Machine.Specifications.Should.0.8.0\lib\net40\Machine.Specifications.Should.dll 52 | True 53 | 54 | 55 | ..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll 56 | True 57 | 58 | 59 | ..\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.dll 60 | True 61 | 62 | 63 | ..\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.Configuration.dll 64 | True 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | {f689cc78-232b-4e2b-8799-2cfb58fd1695} 93 | UnityLog4NetExtension 94 | 95 | 96 | 97 | 98 | 105 | -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/UnityLog4NetExtension.Specs.ncrunchproject: -------------------------------------------------------------------------------- 1 | 2 | false 3 | false 4 | false 5 | true 6 | false 7 | false 8 | false 9 | false 10 | true 11 | true 12 | false 13 | true 14 | true 15 | 60000 16 | 17 | 18 | 19 | AutoDetect 20 | STA 21 | x86 22 | -------------------------------------------------------------------------------- /UnityLog4NetExtension.Specs/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UnityLog4NetExtension.ncrunchsolution: -------------------------------------------------------------------------------- 1 | 2 | 1 3 | True 4 | false 5 | true 6 | UseDynamicAnalysis 7 | UseStaticAnalysis 8 | UseStaticAnalysis 9 | UseStaticAnalysis 10 | 11 | 12 | -------------------------------------------------------------------------------- /UnityLog4NetExtension.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityLog4NetExtension", "UnityLog4NetExtension\UnityLog4NetExtension.csproj", "{F689CC78-232B-4E2B-8799-2CFB58FD1695}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityLog4NetExtension.Specs", "UnityLog4NetExtension.Specs\UnityLog4NetExtension.Specs.csproj", "{83BC3A6D-9DB3-4BFA-817A-9BB4128BD357}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{78427C6D-EDB8-4867-80A1-7299D4B23018}" 11 | ProjectSection(SolutionItems) = preProject 12 | .nuget\NuGet.Config = .nuget\NuGet.Config 13 | .nuget\NuGet.exe = .nuget\NuGet.exe 14 | .nuget\NuGet.targets = .nuget\NuGet.targets 15 | EndProjectSection 16 | EndProject 17 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E8EA7711-0739-4F16-8A39-D969A449CB71}" 18 | ProjectSection(SolutionItems) = preProject 19 | keypair.snk = keypair.snk 20 | EndProjectSection 21 | EndProject 22 | Global 23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 24 | Debug|Any CPU = Debug|Any CPU 25 | Release|Any CPU = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 28 | {F689CC78-232B-4E2B-8799-2CFB58FD1695}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {F689CC78-232B-4E2B-8799-2CFB58FD1695}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {F689CC78-232B-4E2B-8799-2CFB58FD1695}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {F689CC78-232B-4E2B-8799-2CFB58FD1695}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {83BC3A6D-9DB3-4BFA-817A-9BB4128BD357}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {83BC3A6D-9DB3-4BFA-817A-9BB4128BD357}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {83BC3A6D-9DB3-4BFA-817A-9BB4128BD357}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {83BC3A6D-9DB3-4BFA-817A-9BB4128BD357}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.2\lib\NET35 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /UnityLog4NetExtension.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | <?xml version="1.0" encoding="utf-16"?><Profile name="StyleCop"><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSReformatCode>True</CSReformatCode><CSReorderTypeMembers>True</CSReorderTypeMembers><StyleCop.Documentation><SA1600ElementsMustBeDocumented>True</SA1600ElementsMustBeDocumented><SA1604ElementDocumentationMustHaveSummary>True</SA1604ElementDocumentationMustHaveSummary><SA1609PropertyDocumentationMustHaveValueDocumented>True</SA1609PropertyDocumentationMustHaveValueDocumented><SA1611ElementParametersMustBeDocumented>True</SA1611ElementParametersMustBeDocumented><SA1615ElementReturnValueMustBeDocumented>True</SA1615ElementReturnValueMustBeDocumented><SA1617VoidReturnValueMustNotBeDocumented>True</SA1617VoidReturnValueMustNotBeDocumented><SA1618GenericTypeParametersMustBeDocumented>True</SA1618GenericTypeParametersMustBeDocumented><SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes>True</SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes><SA1628DocumentationTextMustBeginWithACapitalLetter>True</SA1628DocumentationTextMustBeginWithACapitalLetter><SA1629DocumentationTextMustEndWithAPeriod>True</SA1629DocumentationTextMustEndWithAPeriod><SA1633SA1641UpdateFileHeader>ReplaceCopyrightElement</SA1633SA1641UpdateFileHeader><SA1639FileHeaderMustHaveSummary>False</SA1639FileHeaderMustHaveSummary><SA1642ConstructorSummaryDocumentationMustBeginWithStandardText>True</SA1642ConstructorSummaryDocumentationMustBeginWithStandardText><SA1643DestructorSummaryDocumentationMustBeginWithStandardText>True</SA1643DestructorSummaryDocumentationMustBeginWithStandardText><SA1644DocumentationHeadersMustNotContainBlankLines>True</SA1644DocumentationHeadersMustNotContainBlankLines></StyleCop.Documentation><StyleCop.Layout><SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine>True</SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine><SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine>True</SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine><SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine>True</SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine><SA1511WhileDoFooterMustNotBePrecededByBlankLine>True</SA1511WhileDoFooterMustNotBePrecededByBlankLine><SA1512SingleLineCommentsMustNotBeFollowedByBlankLine>True</SA1512SingleLineCommentsMustNotBeFollowedByBlankLine><SA1513ClosingCurlyBracketMustBeFollowedByBlankLine>True</SA1513ClosingCurlyBracketMustBeFollowedByBlankLine><SA1514ElementDocumentationHeaderMustBePrecededByBlankLine>True</SA1514ElementDocumentationHeaderMustBePrecededByBlankLine><SA1515SingleLineCommentMustBeProceededByBlankLine>True</SA1515SingleLineCommentMustBeProceededByBlankLine></StyleCop.Layout><StyleCop.Maintainability><SA1119StatementMustNotUseUnnecessaryParenthesis>True</SA1119StatementMustNotUseUnnecessaryParenthesis></StyleCop.Maintainability><StyleCop.Ordering><AlphabeticalUsingDirectives>Alphabetical</AlphabeticalUsingDirectives><ExpandUsingDirectives>FullyQualify</ExpandUsingDirectives><SA1212PropertyAccessorsMustFollowOrder>True</SA1212PropertyAccessorsMustFollowOrder><SA1213EventAccessorsMustFollowOrder>True</SA1213EventAccessorsMustFollowOrder></StyleCop.Ordering><StyleCop.Readability><SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists>True</SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists><SA1106CodeMustNotContainEmptyStatements>True</SA1106CodeMustNotContainEmptyStatements><SA1108BlockStatementsMustNotContainEmbeddedComments>True</SA1108BlockStatementsMustNotContainEmbeddedComments><SA1109BlockStatementsMustNotContainEmbeddedRegions>True</SA1109BlockStatementsMustNotContainEmbeddedRegions><SA1120CommentsMustContainText>True</SA1120CommentsMustContainText><SA1121UseBuiltInTypeAlias>True</SA1121UseBuiltInTypeAlias><SA1122UseStringEmptyForEmptyStrings>True</SA1122UseStringEmptyForEmptyStrings><SA1123DoNotPlaceRegionsWithinElements>True</SA1123DoNotPlaceRegionsWithinElements><SA1124CodeMustNotContainEmptyRegions>True</SA1124CodeMustNotContainEmptyRegions></StyleCop.Readability><StyleCop.Spacing><SA1001CommasMustBeSpacedCorrectly>True</SA1001CommasMustBeSpacedCorrectly><SA1005SingleLineCommentsMustBeginWithSingleSpace>True</SA1005SingleLineCommentsMustBeginWithSingleSpace><SA1006PreprocessorKeywordsMustNotBePrecededBySpace>True</SA1006PreprocessorKeywordsMustNotBePrecededBySpace><SA1021NegativeSignsMustBeSpacedCorrectly>True</SA1021NegativeSignsMustBeSpacedCorrectly><SA1022PositiveSignsMustBeSpacedCorrectly>True</SA1022PositiveSignsMustBeSpacedCorrectly><SA1025CodeMustNotContainMultipleWhitespaceInARow>True</SA1025CodeMustNotContainMultipleWhitespaceInARow></StyleCop.Spacing><CSUpdateFileHeader>True</CSUpdateFileHeader></Profile> 3 | StyleCop 4 | Copyright & Licence 5 | This software is licensed under the MIT License 6 | 7 | 8 | Copyright (C) 2012-14, Rob Levine 9 | 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), 13 | to deal in the Software without restriction, including without limitation 14 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 15 | and/or sell copies of the Software, and to permit persons to whom the 16 | Software is furnished to do so, subject to the following conditions: 17 | 18 | 19 | The above copyright notice and this permission notice shall be included in 20 | all copies or substantial portions of the Software. 21 | 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 29 | IN THE SOFTWARE. 30 | 31 | [Source code: https://github.com/roblevine/UnityLoggingExtensions] 32 | <Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private, Protected, ProtectedInternal, Internal, Public" Description="Machine.Specifications Rules"><ElementKinds><Kind Name="Machine.Specifications_Behavior" /><Kind Name="Machine.Specifications_Context" /><Kind Name="Machine.Specifications_ContextBase" /><Kind Name="Machine.Specifications_Specification" /><Kind Name="Machine.Specifications_SupportingField" /><Kind Name="Machine.Specifications_Field" /><Kind Name="Machine.Specifications_Constant" /><Kind Name="Machine.Specifications_Local" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aa_bb" /></Policy> 33 | <data><IncludeFilters /><ExcludeFilters /></data> 34 | <data /> 35 | False -------------------------------------------------------------------------------- /UnityLog4NetExtension/CreationStackReporter/CreationStackReporterExtension.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using Microsoft.Practices.Unity; 34 | using Microsoft.Practices.Unity.ObjectBuilder; 35 | using UnityLog4NetExtension.CreationStackTracker; 36 | 37 | namespace UnityLog4NetExtension.CreationStackReporter 38 | { 39 | /// 40 | /// 41 | public class CreationStackReporterExtension : UnityContainerExtension 42 | { 43 | #region Methods 44 | 45 | /// 46 | /// 47 | protected override void Initialize() 48 | { 49 | Context.Strategies.AddNew(UnityBuildStage.TypeMapping); 50 | Context.Strategies.AddNew(UnityBuildStage.TypeMapping); 51 | } 52 | 53 | #endregion 54 | } 55 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension/CreationStackReporter/CreationStackReporterStrategy.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using Microsoft.Practices.ObjectBuilder2; 34 | using UnityLog4NetExtension.CreationStackTracker; 35 | 36 | namespace UnityLog4NetExtension.CreationStackReporter 37 | { 38 | /// 39 | /// 40 | public class UnityObjectCreationStackReporterStrategy : BuilderStrategy 41 | { 42 | #region Public Methods and Operators 43 | 44 | /// 45 | /// 46 | /// 47 | /// 48 | public override void PreBuildUp(IBuilderContext context) 49 | { 50 | var policy = context.Policies.Get(buildKey: null, localOnly: true); 51 | 52 | if (policy.TypeStack.Count > 1 && policy.TypeStack.Peek(0) == typeof (UnityObjectCreationStack)) 53 | { 54 | context.Existing = new UnityObjectCreationStack(policy.TypeStack.Items); 55 | } 56 | 57 | base.PreBuildUp(context); 58 | } 59 | 60 | #endregion 61 | } 62 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension/CreationStackTracker/CreationStackTrackerExtension.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using Microsoft.Practices.Unity; 34 | using Microsoft.Practices.Unity.ObjectBuilder; 35 | 36 | namespace UnityLog4NetExtension.CreationStackTracker 37 | { 38 | /// 39 | /// 40 | public class CreationStackTrackerExtension : UnityContainerExtension 41 | { 42 | #region Methods 43 | 44 | /// 45 | /// 46 | protected override void Initialize() 47 | { 48 | Context.Strategies.AddNew(UnityBuildStage.TypeMapping); 49 | } 50 | 51 | #endregion 52 | } 53 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension/CreationStackTracker/CreationStackTrackerPolicy.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using System; 34 | 35 | namespace UnityLog4NetExtension.CreationStackTracker 36 | { 37 | /// 38 | /// 39 | public class CreationStackTrackerPolicy : ICreationStackTrackerPolicy 40 | { 41 | #region Fields 42 | 43 | /// 44 | /// 45 | private readonly PeekableStack typeStack = new PeekableStack(); 46 | 47 | #endregion 48 | 49 | #region Public Properties 50 | 51 | /// 52 | /// 53 | public PeekableStack TypeStack 54 | { 55 | get { return typeStack; } 56 | } 57 | 58 | #endregion 59 | } 60 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension/CreationStackTracker/CreationStackTrackerStrategy.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using System; 34 | using System.Linq; 35 | using Microsoft.Practices.ObjectBuilder2; 36 | 37 | namespace UnityLog4NetExtension.CreationStackTracker 38 | { 39 | /// 40 | /// 41 | public class CreationStackTrackerStrategy : BuilderStrategy 42 | { 43 | #region Public Methods and Operators 44 | 45 | /// 46 | /// 47 | /// 48 | /// 49 | public override void PostBuildUp(IBuilderContext context) 50 | { 51 | var policy = context.Policies.Get(buildKey: null, localOnly: true); 52 | 53 | if (policy.TypeStack.Count > 0) 54 | { 55 | policy.TypeStack.Pop(); 56 | } 57 | 58 | base.PostBuildUp(context); 59 | } 60 | 61 | /// 62 | /// 63 | /// 64 | /// 65 | public override void PreBuildUp(IBuilderContext context) 66 | { 67 | var policy = context.Policies.Get(buildKey: null, localOnly: true); 68 | if (policy == null) 69 | { 70 | context.Policies.Set(typeof (ICreationStackTrackerPolicy), new CreationStackTrackerPolicy(), null); 71 | policy = context.Policies.Get(buildKey: null, localOnly: true); 72 | } 73 | 74 | policy.TypeStack.Push(context.BuildKey.Type); 75 | 76 | base.PreBuildUp(context); 77 | } 78 | 79 | #endregion 80 | 81 | #region Methods 82 | 83 | /// 84 | /// 85 | /// 86 | /// 87 | /// 88 | /// 89 | private object ReportStack(PeekableStack typeStack) 90 | { 91 | return string.Join(", ", typeStack.Items.Select(s => s.Name)); 92 | } 93 | 94 | #endregion 95 | } 96 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension/CreationStackTracker/ICreationStackTrackerPolicy.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using System; 34 | using Microsoft.Practices.ObjectBuilder2; 35 | 36 | namespace UnityLog4NetExtension.CreationStackTracker 37 | { 38 | /// 39 | /// 40 | public interface ICreationStackTrackerPolicy : IBuilderPolicy 41 | { 42 | #region Public Properties 43 | 44 | /// 45 | /// 46 | PeekableStack TypeStack { get; } 47 | 48 | #endregion 49 | } 50 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension/CreationStackTracker/LoggingBuilderStrategy.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // TODO: Update copyright text. 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace UnityExtensions.ObjectCreationStackTracking 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | 14 | using Microsoft.Practices.ObjectBuilder2; 15 | using Microsoft.Practices.Unity; 16 | using Microsoft.Practices.Unity.ObjectBuilder; 17 | 18 | /// 19 | /// TODO: Update summary. 20 | /// 21 | public class LoggingBuilderStrategy : BuilderStrategy 22 | { 23 | private readonly UnityBuildStage unityBuildStage; 24 | 25 | public LoggingBuilderStrategy(UnityBuildStage unityBuildStage) 26 | { 27 | this.unityBuildStage = unityBuildStage; 28 | } 29 | 30 | public UnityBuildStage Stage 31 | { 32 | get 33 | { 34 | return this.unityBuildStage; 35 | } 36 | } 37 | 38 | public override void PreBuildUp(IBuilderContext context) 39 | { 40 | Console.WriteLine("UnityBuildStage: {0}, {1}", this.unityBuildStage, "PreBuildUp"); 41 | base.PreBuildUp(context); 42 | } 43 | 44 | public override void PostBuildUp(IBuilderContext context) 45 | { 46 | Console.WriteLine("UnityBuildStage: {0}, {1}", this.unityBuildStage, "PostBuildUp"); 47 | base.PostBuildUp(context); 48 | } 49 | 50 | public override void PreTearDown(IBuilderContext context) 51 | { 52 | Console.WriteLine("UnityBuildStage: {0}, {1}", this.unityBuildStage, "PreTearDown"); 53 | base.PreTearDown(context); 54 | } 55 | 56 | public override void PostTearDown(IBuilderContext context) 57 | { 58 | Console.WriteLine("UnityBuildStage: {0}, {1}", this.unityBuildStage, "PostTearDown"); 59 | base.PostTearDown(context); 60 | } 61 | } 62 | 63 | public class LoggingBuilderExtension : UnityContainerExtension 64 | { 65 | protected override void Initialize() 66 | { 67 | var builder = new LoggingBuilderStrategy(UnityBuildStage.Creation); 68 | this.Context.Strategies.Add(builder, builder.Stage); 69 | 70 | builder = new LoggingBuilderStrategy(UnityBuildStage.Initialization); 71 | this.Context.Strategies.Add(builder, builder.Stage); 72 | 73 | builder = new LoggingBuilderStrategy(UnityBuildStage.Lifetime); 74 | this.Context.Strategies.Add(builder, builder.Stage); 75 | 76 | builder = new LoggingBuilderStrategy(UnityBuildStage.PostInitialization); 77 | this.Context.Strategies.Add(builder, builder.Stage); 78 | 79 | builder = new LoggingBuilderStrategy(UnityBuildStage.PreCreation); 80 | this.Context.Strategies.Add(builder, builder.Stage); 81 | 82 | builder = new LoggingBuilderStrategy(UnityBuildStage.Setup); 83 | this.Context.Strategies.Add(builder, builder.Stage); 84 | 85 | builder = new LoggingBuilderStrategy(UnityBuildStage.TypeMapping); 86 | this.Context.Strategies.Add(builder, builder.Stage); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /UnityLog4NetExtension/CreationStackTracker/UnityObjectCreationStack.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using System; 34 | using System.Collections.Generic; 35 | 36 | namespace UnityLog4NetExtension.CreationStackTracker 37 | { 38 | /// 39 | /// 40 | public class UnityObjectCreationStack 41 | { 42 | #region Fields 43 | 44 | /// 45 | /// 46 | private readonly List items; 47 | 48 | #endregion 49 | 50 | #region Constructors and Destructors 51 | 52 | /// 53 | /// 54 | /// 55 | /// 56 | public UnityObjectCreationStack(IEnumerable stack) 57 | { 58 | items = new List(stack); 59 | } 60 | 61 | #endregion 62 | 63 | #region Public Properties 64 | 65 | /// 66 | /// 67 | public IEnumerable Items 68 | { 69 | get { return items; } 70 | } 71 | 72 | #endregion 73 | 74 | #region Public Methods and Operators 75 | 76 | /// 77 | /// 78 | /// 79 | /// 80 | /// 81 | /// 82 | public Type Peek(int peekBack = 0) 83 | { 84 | return items[items.Count - 1 - peekBack]; 85 | } 86 | 87 | #endregion 88 | } 89 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension/Log4Net/Log4NetExtension.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using Microsoft.Practices.Unity; 34 | using Microsoft.Practices.Unity.ObjectBuilder; 35 | using UnityLog4NetExtension.CreationStackTracker; 36 | 37 | namespace UnityLog4NetExtension.Log4Net 38 | { 39 | /// 40 | /// 41 | public class Log4NetExtension : UnityContainerExtension 42 | { 43 | #region Methods 44 | 45 | /// 46 | /// 47 | protected override void Initialize() 48 | { 49 | Context.Strategies.AddNew(UnityBuildStage.TypeMapping); 50 | Context.Strategies.AddNew(UnityBuildStage.TypeMapping); 51 | } 52 | 53 | #endregion 54 | } 55 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension/Log4Net/Log4NetStrategy.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using log4net; 34 | using Microsoft.Practices.ObjectBuilder2; 35 | using UnityLog4NetExtension.CreationStackTracker; 36 | 37 | namespace UnityLog4NetExtension.Log4Net 38 | { 39 | /// 40 | /// 41 | public class Log4NetStrategy : BuilderStrategy 42 | { 43 | #region Public Methods and Operators 44 | 45 | /// 46 | /// 47 | /// 48 | /// 49 | public override void PreBuildUp(IBuilderContext context) 50 | { 51 | var policy = context.Policies.Get(buildKey: null, localOnly: true); 52 | 53 | if (policy.TypeStack.Count >= 2 && policy.TypeStack.Peek(0) == typeof (ILog)) 54 | { 55 | context.Existing = LogManager.GetLogger(policy.TypeStack.Peek(1)); 56 | } 57 | 58 | base.PreBuildUp(context); 59 | } 60 | 61 | #endregion 62 | } 63 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension/PeekableStack.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using System.Collections.Generic; 34 | 35 | namespace UnityLog4NetExtension 36 | { 37 | /// 38 | /// 39 | /// 40 | /// 41 | public class PeekableStack 42 | { 43 | #region Fields 44 | 45 | /// 46 | /// 47 | private readonly List list; 48 | 49 | #endregion 50 | 51 | #region Constructors and Destructors 52 | 53 | /// 54 | /// 55 | public PeekableStack() 56 | { 57 | list = new List(); 58 | } 59 | 60 | /// 61 | /// 62 | /// 63 | /// 64 | public PeekableStack(IEnumerable initialItems) 65 | { 66 | list = new List(initialItems); 67 | } 68 | 69 | #endregion 70 | 71 | #region Public Properties 72 | 73 | /// 74 | /// 75 | public int Count 76 | { 77 | get { return list.Count; } 78 | } 79 | 80 | /// 81 | /// 82 | public IEnumerable Items 83 | { 84 | get { return list.ToArray(); } 85 | } 86 | 87 | #endregion 88 | 89 | #region Public Methods and Operators 90 | 91 | /// 92 | /// 93 | /// 94 | /// 95 | /// 96 | /// 97 | public T Peek(int depth) 98 | { 99 | var index = list.Count - 1 - depth; 100 | return list[index]; 101 | } 102 | 103 | /// 104 | /// 105 | /// 106 | /// 107 | public T Pop() 108 | { 109 | var index = list.Count - 1; 110 | T ret = list[index]; 111 | list.RemoveAt(index); 112 | return ret; 113 | } 114 | 115 | /// 116 | /// 117 | /// 118 | /// 119 | public void Push(T obj) 120 | { 121 | list.Add(obj); 122 | } 123 | 124 | #endregion 125 | } 126 | } -------------------------------------------------------------------------------- /UnityLog4NetExtension/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | #region Copyright & License 2 | 3 | // This software is licensed under the MIT License 4 | // 5 | // 6 | // Copyright (C) 2012-14, Rob Levine 7 | // 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy 10 | // of this software and associated documentation files (the "Software"), 11 | // to deal in the Software without restriction, including without limitation 12 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | // and/or sell copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following conditions: 15 | // 16 | // 17 | // The above copyright notice and this permission notice shall be included in 18 | // all copies or substantial portions of the Software. 19 | // 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | // IN THE SOFTWARE. 28 | // 29 | // [Source code: https://github.com/roblevine/UnityLoggingExtensions] 30 | 31 | #endregion 32 | 33 | using System.Reflection; 34 | using System.Runtime.InteropServices; 35 | 36 | // General Information about an assembly is controlled through the following 37 | // set of attributes. Change these attribute values to modify the information 38 | // associated with an assembly. 39 | 40 | [assembly: AssemblyTitle("UnityLog4NetExtension")] 41 | [assembly: AssemblyDescription("A simple extension to Unity that enables log4net ILog dependencies to be injected into consuming classes, with the ILog instance being configured as the correct logger for the consuming class.")] 42 | [assembly: AssemblyConfiguration("")] 43 | [assembly: AssemblyCompany("INEX Solutions Ltd")] 44 | [assembly: AssemblyProduct("UnityLog4NetExtension")] 45 | [assembly: AssemblyCopyright("Copyright © INEX Solutions Ltd 2012")] 46 | [assembly: AssemblyTrademark("")] 47 | [assembly: AssemblyCulture("")] 48 | 49 | // Setting ComVisible to false makes the types in this assembly not visible 50 | // to COM components. If you need to access a type in this assembly from 51 | // COM, set the ComVisible attribute to true on that type. 52 | 53 | [assembly: ComVisible(false)] 54 | 55 | // The following GUID is for the ID of the typelib if this project is exposed to COM 56 | 57 | [assembly: Guid("69aa241b-5525-4d87-8d50-b4a3870596b7")] 58 | 59 | // Version information for an assembly consists of the following four values: 60 | // Major Version 61 | // Minor Version 62 | // Build Number 63 | // Revision 64 | // You can specify all the values or you can default the Build and Revision Numbers 65 | // by using the '*' as shown below: 66 | // [assembly: AssemblyVersion("1.0.*")] 67 | 68 | [assembly: AssemblyVersion("1.1.0.0")] 69 | [assembly: AssemblyFileVersion("1.1.0.0")] -------------------------------------------------------------------------------- /UnityLog4NetExtension/UnityLog4NetExtension.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {F689CC78-232B-4E2B-8799-2CFB58FD1695} 9 | Library 10 | Properties 11 | UnityLog4NetExtension 12 | UnityLog4NetExtension 13 | v4.0 14 | 512 15 | ..\ 16 | true 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | true 27 | 28 | 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | true 36 | 37 | 38 | true 39 | 40 | 41 | keypair.snk 42 | 43 | 44 | 45 | False 46 | ..\packages\log4net.2.0.3\lib\net40-full\log4net.dll 47 | 48 | 49 | False 50 | ..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll 51 | 52 | 53 | False 54 | ..\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.dll 55 | 56 | 57 | False 58 | ..\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.Configuration.dll 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | "$(SolutionDir).nuget\Nuget.exe" pack "$(ProjectPath)" -BasePath "$(ProjectDir)" -OutputDirectory "$(TargetDir)" -Prop Configuration=$(ConfigurationName) 89 | 90 | 97 | -------------------------------------------------------------------------------- /UnityLog4NetExtension/UnityLog4NetExtension.ncrunchproject: -------------------------------------------------------------------------------- 1 | 2 | false 3 | false 4 | false 5 | true 6 | false 7 | false 8 | false 9 | false 10 | true 11 | true 12 | false 13 | true 14 | true 15 | 60000 16 | 17 | 18 | 19 | AutoDetect 20 | STA 21 | x86 22 | 23 | 24 | .* 25 | 26 | 27 | -------------------------------------------------------------------------------- /UnityLog4NetExtension/UnityLog4NetExtension.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | Rob Levine 8 | Rob Levine 9 | http://blog.roblevine.co.uk/net/using-log4net-with-unity/ 10 | https://github.com/roblevine/UnityLoggingExtensions/blob/master/license.txt 11 | false 12 | $description$ 13 | Initial NuGet package. 14 | Copyright 2012 15 | Unity Log4Net 16 | 17 | 18 | -------------------------------------------------------------------------------- /UnityLog4NetExtension/createNugetPackage.cmd: -------------------------------------------------------------------------------- 1 | ..\.nuget\nuget.exe pack UnityLog4NetExtension.csproj -------------------------------------------------------------------------------- /UnityLog4NetExtension/keypair.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roblevine/UnityLog4NetExtension/7a39c0f417d018c7af6f417d55fcb19bffd1810b/UnityLog4NetExtension/keypair.snk -------------------------------------------------------------------------------- /UnityLog4NetExtension/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /keypair.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roblevine/UnityLog4NetExtension/7a39c0f417d018c7af6f417d55fcb19bffd1810b/keypair.snk -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT License 2 | 3 | Copyright (C) 2012, Rob Levine 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), 7 | to deal in the Software without restriction, including without limitation 8 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | and/or sell copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | IN THE SOFTWARE. 22 | 23 | --------------------------------------------------------------------------------