1

Is it possible to use a machine.config setting inside the Nlog.config?

Example

       <nlog>
          ...
          <target name="database" xsi:type="Database" 
keepConnection="true" dbDatabase="xxx" 
dbHost="**MACHINE_CONFIG_SETTING**" 
commandType="StoredProcedure"  dbProvider="System.Data.SqlClient" dbUserName="**MACHINE_CONFIG_SETTING**"
 dbPassword="**MACHINE_CONFIG_SETTING**" 
  connectionString="**MACHINE_CONFIG_SETTING**"
          commandText="stored_proc">
    </nlog>

We have the dbhost name and dbUsername in the machine config so I don't really want to duplicate that information in the Nlog config. I don't want to put the whole of the Nlog configuration in the machine config if I can help it.

Any help would be very much appreciated.

DazedandConfused
  • 357
  • 5
  • 16

1 Answers1

0

This should be possible, but you can't overwrite it partly.

You can also use <include file="${basedir}/${machinename}.config"/> for reuse, which is a bit more flexible.

Julian
  • 33,915
  • 22
  • 119
  • 174
  • Thanks for your answer. I actually used the LogManager.Configuration to get the target and cast it to database target in my code and then the System.Configuration to get config I needed from the machine config. Worked a treat – DazedandConfused Apr 16 '16 at 17:36