0

We are using a marketplace module that has a config file like this:

<appender name="DBLogAppender" type="Feature.DBLogAppender.SitecoreDatabaseLogAppender, Feature.DBLogAppender">
....
<param name="ConnectionString" value="<connectionstring>"/> //core db conn string
....
</appender>

All the non local environments are containers and the database names vary for each of them.

I would like to dynamically refer the connection string of the core database here - <connectionstring>

Is it possible.

Patch config XML:

<appender patch:after="*[@name=LogFileAppender]" name="SCBasicsAuditTrailDBAppender" type="SCBasics.AuditTrail.Appender.SitecoreDatabaseLogAppender,
              SCBasics.AuditTrail" >
              
              
      <!-- Filter items where message field start with 'AUDIT....' -->
      <filter type="log4net.Filter.StringMatchFilter">
        <regexToMatch value="^AUDIT" />
      </filter>

 

      <!-- Deny all other items -->
      <filter type="log4net.Filter.DenyAllFilter" />
      <!--his is because logs are buffered until a given buffersize is reached.
      The default value is 512, but you can lower this by modifying the following line of code-->
      <bufferSize value="1" />
      <param name="ConnectionType" value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <!--Double SLASH is Very Important-->
      <param name="ConnectionString" value="Data Source=ABC100\\SQLEXPRESS;Database=SCDemo_Core;user id=sa;password=abc@123"/>
      
      <param name="CommandText" value="INSERT INTO tbl_AuditTrail_Logs ([Date],[Thread],[Level],[Logger],[Message],[Exception], 
 

[SCUser], [SCAction], [SCItemPath], [SCLanguage] , [SCVersion] , [SCItemId], [SiteName],[SCMisc]) VALUES (@log_date, 

 

@thread, @log_level, @logger, @message, @exception, @scuser,  @scaction, @scitempath, @sclanguage, @scversion, 

 

@scitemid, @sitename, @scmisc)" />
      <param name="Parameter">
        <param name="ParameterName" value="@log_date" />
        <param name="DbType" value="DateTime" />
        <param name="Layout" type="log4net.Layout.PatternLayout">
          <param name="ConversionPattern" value="%d{yyyy&apos;-&apos;MM&apos;-&apos;dd 

 

HH&apos;:&apos;mm&apos;:&apos;ss&apos;.&apos;fff}" />
        </param>
      </param>
      <param name="Parameter">
        <param name="ParameterName" value="@thread" />
        <param name="DbType" value="String" />
        <param name="Size" value="255" />
        <param name="Layout" type="log4net.Layout.PatternLayout">
          <param name="ConversionPattern" value="%t" />
        </param>
      </param>
      <param name="Parameter">
        <param name="ParameterName" value="@log_level" />
        <param name="DbType" value="String" />
        <param name="Size" value="50" />
        <param name="Layout" type="log4net.Layout.PatternLayout">
          <param name="ConversionPattern" value="%p" />
        </param>
      </param>
      <param name="Parameter">
        <param name="ParameterName" value="@logger" />
        <param name="DbType" value="String" />
        <param name="Size" value="255" />
        <param name="Layout" type="log4net.Layout.PatternLayout">
          <param name="ConversionPattern" value="%c" />
        </param>
      </param>
      <param name="Parameter">
        <param name="ParameterName" value="@message" />
        <param name="DbType" value="String" />
        <param name="Size" value="4000" />
        <param name="Layout" type="log4net.Layout.PatternLayout">
          <param name="ConversionPattern" value="%m" />
        </param>
      </param>
      <param name="Parameter">
        <param name="ParameterName" value="@exception" />
        <dbType value="String" />
        <size value="2000" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </param>
      <param name="Parameter">
        <param name="ParameterName" value="@scuser" />
        <dbType value="String" />
        <size value="255" />
        <layout type="SCBasics.AuditTrail.Log4NetLayout.PropertyLayout,SCBasics.AuditTrail">
          <param name="PropertyName" value="scuser" />
        </layout>
      </param>
      <param name="Parameter">
        <param name="ParameterName" value="@scaction" />
        <dbType value="String" />
        <size value="255" />
        <layout type="SCBasics.AuditTrail.Log4NetLayout.PropertyLayout,SCBasics.AuditTrail">
          <param name="PropertyName" value="scaction" />
        </layout>
      </param>
      <param name="Parameter">
        <param name="ParameterName" value="@scitempath" />
        <dbType value="String" />
        <size value="255" />
        <layout type="SCBasics.AuditTrail.Log4NetLayout.PropertyLayout,SCBasics.AuditTrail">
          <param name="PropertyName" value="scitempath" />
        </layout>
      </param>
      <param name="Parameter">
        <param name="ParameterName" value="@sclanguage" />
        <dbType value="String" />
        <size value="255" />
        <layout type="SCBasics.AuditTrail.Log4NetLayout.PropertyLayout,SCBasics.AuditTrail">
          <param name="PropertyName" value="sclanguage" />
        </layout>
      </param>
      <param name="Parameter">
        <param name="ParameterName" value="@scversion" />
        <dbType value="String" />
        <size value="255" />
        <layout type="SCBasics.AuditTrail.Log4NetLayout.PropertyLayout,SCBasics.AuditTrail">
          <param name="PropertyName" value="scversion" />
        </layout>
      </param>      
      <param name="Parameter">
        <param name="ParameterName" value="@scitemid" />
        <dbType value="String" />
        <size value="38" />
        <layout type="SCBasics.AuditTrail.Log4NetLayout.PropertyLayout,SCBasics.AuditTrail">
          <param name="PropertyName" value="scitemid" />
        </layout>
      </param>
      <param name="Parameter">
        <param name="ParameterName" value="@sitename" />
        <dbType value="String" />
        <size value="255" />
        <layout type="SCBasics.AuditTrail.Log4NetLayout.PropertyLayout,SCBasics.AuditTrail">
          <param name="PropertyName" value="sitename" />
        </layout>
      </param>
      <param name="Parameter">
        <param name="ParameterName" value="@scmisc" />
        <dbType value="String" />
        <size value="255" />
        <layout type="SCBasics.AuditTrail.Log4NetLayout.PropertyLayout,SCBasics.AuditTrail">
          <param name="PropertyName" value="scmisc" />
        </layout>
      </param>
    </appender>
3
  • Actually my answer may be wrong. I would need to know the full XML path of the configuration you are attempting to patch, to be able to answer.
    – Mark Cassidy
    Jun 16 at 7:35
  • @MarkCassidy I have added the xml. Please have a look.
    – Qwerty
    Jun 16 at 7:42
  • 1
    Ok. Well that section of configuration CAN be patched. What you cannot do however, is patch in the value from the "core" connection string as you ask for - the Sitecore patch configuration mechanic can only "see" inside the <sitecore> scope.
    – Mark Cassidy
    Jun 16 at 7:50
4

You cannot.

You can only patch settings in the app_config/sitecore.config file. Settings in other files such as the web.config and app_config/layers.config files cannot be patched. If you need to change the settings in these files, you must edit them directly.

Source: https://doc.sitecore.com/developers/90/platform-administration-and-architecture/en/use-a-patch-file-to-customize-the-sitecore-configuration.html

Because of the above, you cannot reach the connectionStrings part of the configuration and therefore you will not be able to patch in a value from there (e.g. the value for "core") in another location in the configuration.

The Sitecore Module you are using is doing it wrong, basically. Instead of requiring a connection string to be set up, it should be asking for a connection string name.

1
  • We can refer global variables (sc:variable) like $(dataFolder). Is there anything we co do similar. The challenge is, we cannot declare global variable also as the db names are varying.
    – Qwerty
    Jun 16 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.