Nicely Display the log4net.*.config Files
So I have created the Debug and Release log4net config files. So we have BASE which is transformed by either Debug or Release (depending on which is selected) and ultimately creates log4net.config which is the configuration file that our application will use. However, as you can see below, all of these files are at the root level of the project where Web.config has the transformations located as sub-files under Web.config.
We can make this happen for log4net as well. As we did in Part 1 of this blog, Unload the project, then edit the .csproj file. If you search for Web.Release.config, you should find some lines that look similar to (notice the <DependentUpon> tag):
<Content Include="Web.config" />
<Content Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
If you search for log4net.Release.config and log4net.Debug.config and add this tag to their “content” tags like this (changing Web.config to log4net.config):
<Content Include="log4net.config">
<SubType>Designer</SubType>
</Content>
<Content Include="log4net.BASE.config">
<SubType>Designer</SubType>
</Content>
<Content Include="log4net.Release.config">
<DependentUpon>log4net.config</DependentUpon>
<SubType>Designer</SubType>
</Content>
<Content Include="log4net.Debug.config">
<DependentUpon>log4net.config</DependentUpon>
<SubType>Designer</SubType>
</Content>
If we then Save, close and re-load the project, we have a nicely formatted config with the transforms sitting nicely beneath the log4net.config (just like Web.config):
In part 5 of this series, I will show you a Visual Studio Extension called SlowCheetah that makes the process of creating and managing configuration file for any configuration as easy as it is for Web.config. It even adds the ability to Preview your transforms.
Transforms for ANY .config file: 5 Part Series
Part 1: Transforms on Build
This first part does an overview of the default behavior of transforms. It then shows how you can plug into the MSBuild process and apply your transforms at Build time rather than the default publish time.
Part 2: New Config Profiles
The second part of the series shows how to create a new solution configuration and the nuances of what happens behind the scenes (in case you want to delete a configuration). It also discusses having a local development configuration specific to an individual developer.
Part 3: Other Config Files
The third part discusses how to add a configuration for another element of the application (using log4net as an example). This post shows how this process differs from the handling of Web.config.
Part 4: Making the transforms look nice
This fourth part is just a quickie to show how you can manually make your other configuration files sit under their respective parent files.
Part 5: SlowCheetah & Advanced
This fifth and final post is where I try to bring together all of the elements from the previous posts together and introduce a Visual Studio extension that allows much of the previous posts to be accomplished easily and automatically.
No comments:
Post a Comment