0

On local debug configuration I want to logging in txt file. It's work. Logging to Azure Blob Storage work fine too. But I want configure the second to work only on "Azure debug" configuration.

I have created simple tranformation in web.debug.azure.config.

-> Web.config

<log4net debug="true">
<root>
  <level value="Info" />
  <appender-ref ref="Appender"/>
</root>
<appender name="Appender" type="log4net.Appender.RollingFileAppender" >
 // Configuration stuff
</appender>

And it's set for "Debug" build configuration. While build for "Azure debug" I want to replace the "" with it: -> Web.Debug.Azure.config

 <appender xdt:Transform="Replace" xdt:Locator="Match(name)" name="Appender" type="log4net.Appender.AzureAppendBlobAppender, log4net.Appender.Azure">
// Configuration stuff
</appender>

And when I do it. The first still working and the second no. Why? How to do it?

Nerf
  • 938
  • 1
  • 13
  • 30
  • What does _"The first still working and the second no"_ mean exactly? Do you understand the web site runs from your source directory on the web.config present there, not the transformed one? – CodeCaster May 04 '16 at 10:21
  • I know so I want to transform the log4net section. – Nerf May 04 '16 at 10:23
  • Yes, that part is clear from your question. What isn't clear is what is or isn't working. You do know that the [configuration transform is only applied on deploy, not on debug](http://stackoverflow.com/questions/3305096/how-can-i-use-web-debug-config-in-the-built-in-visual-studio-debugger-server)? – CodeCaster May 04 '16 at 10:23
  • So I can't test if it is work fine localy? – Nerf May 04 '16 at 10:43
  • 1
    Well _if_ your question is _"How can I test configuration transforms without deploying the web application "_, them try searching for that: there are ways to do so. – CodeCaster May 04 '16 at 10:44

1 Answers1

0

Unload the C# Project and modify the csproj file to add an AfterBuild Task, so your Web.Debug.Config transforms to Web.Azure.Debug.Config

Modify the Visual Studio version if required in the below import project path - Microsoft\VisualStudio*v14.0\WebApplications\Microsoft.WebApplication.targets*

Note : You might need to use Slow Cheetah or similar if you want to do this on a CI server if does not have Visual Studio instance as the project ships with Visual Studio.

  <PropertyGroup>

        <TransformInputFile>Web.config</TransformInputFile>
        <TransformFile>Web.Debug.config</TransformFile>
        <TransformOutputFile>Web.Debug.Azure.config</TransformOutputFile>    
      </PropertyGroup>

 <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" />

<Target Name="AfterBuild">
        <Message Text="=== Transform to Azure Debug ===" />
        <TransformXml Source="$(TransformInputFile)" Transform="$(TransformFile)" Destination="$(TransformOutputFile)" />
      </Target>
Vinay
  • 954
  • 8
  • 13