Search code examples
azureazure-web-app-servicelog4netweb.config-transform

Log4Net web.config transform wont work


Im trying to get a web.config transform to work for Log4Net when I publish to my Azure app, but it just never changes. I have several other items in the transform and they work just fine. Heres what I have

<log4net>
    <appender name="AdoNetAppender"  type="log4net.Appender.AdoNetAppender"  xdt:Locator="Match(name)">
      <connectionString value="Server=production server connection details here" xdt:Transform="Replace"/>
    </appender>
  </log4net>

can anyone tell me where I'm going wrong ?

This is my config transform file (live details removed)

<?xml version="1.0" encoding="utf-8"?>

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <log4net>
    <appender name="AdoNetAppender"  type="log4net.Appender.AdoNetAppender"  xdt:Locator="Match(name)">
      <connectionString value="Server=server details here" xdt:Transform="SetAttributes"/>
    </appender>
  </log4net>

  <connectionStrings>
    <add name="AzureWebJobsDashboard" connectionString="DefaultEndpointsProtocol=https;AccountName=liveversionhere;AccountKey=liveversionhere;EndpointSuffix=core.windows.net" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    <add name="AzureWebJobsStorage"  connectionString="DefaultEndpointsProtocol=https;AccountName=liveversionhere;AccountKey=liveversionhere;EndpointSuffix=core.windows.net"  xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    <add name="DefaultConnection" connectionString="Data Source=liveversionhere" providerName="System.Data.SqlClient"  xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    <add name="CHPDataContext" connectionString="Data Source=liveversionhere" providerName="System.Data.SqlClient"  xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    <add name="elmah" connectionString="Data Source=liveversionhere" providerName="System.Data.SqlClient"  xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>

  <appSettings>
    <add key="ida:redirectUri" value="liveversionhere" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
    <add key="ida:ClientId" value=liveversionhere  xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
    <add key="ida:ClientSecret" value=liveversionhere"  xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
    <add key="ida:TenantId" value=liveversionhere  xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
    
  </appSettings>
  
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
   
  </system.web>
</configuration>

**UPDATE

I've changed the transform (see below) and it still doesn't work. does anyone have any clue whats going on here ? this is supposed to be pretty straightforward yet Im finding myself wasting hours of my time just to get something this basic to actually work

<log4net>
    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender" xdt:Locator="Match(name)">
      <connectionString name="Log4NetConn" value="Server=productionsdetailshere" xdt:Locator="Match(name)" xdt:Transform="Replace"/>
    </appender>
  </log4net>


Solution

  • had to replace the entire log4net section

    the connectionstring simply didnt work