how to set custom value in log4net.config

1.5k Views Asked by At

I have a custom appender in another dll and I want to set a value "Element.MachineName" inside the log4net.config file.

It works with a static value like : <appName ="SomeName" /> but how can I set this value with Element.MachineName ?

<appender name="SomeAppender" type="ConsoleApplication1.SomeAppender">
    <appName value="someName"/>
    <host value="how to set the host to this variable?" />
        <layout type="log4net.Layout.LayoutPattern">
          <conversionPattern value="[%date{MM/dd/yyyy hh:mm:ss tt}] %property{HostName} [%-5level] [%class]-[%method] - [%message] %newline" />
        </layout>
  </appender>
1

There are 1 best solutions below

0
On BEST ANSWER

You could use the global context for this purpose. See this log4net page, it explains how you can set the properties. In your settings you could use something like this:

<appender name="SomeAppender" type="ConsoleApplication1.SomeAppender">
  <file value="Log\Sessions\%property{LogFileName}.log" />
  <maxFiles value="1000" />
  <layout type="log4net.Layout.PatternLayout" value="%date %-5level - %message%newline" />
</appender>