Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you log the machine name via log4net?

People also ask

Where do log4net logs go?

In your case, the log file will be in bin\Debug\netcoreapp3.


You can use the pre-populated property log4net:HostName, for example:

<conversionPattern value="%property{log4net:HostName}" />

This way you don't need to populate the MDC.


you can create a parameter similar to the following:

<parameter>
  <parameterName value="@machine" />
  <dbType value="String" />
  <size value="255" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%X{machine}" />
  </layout>
</parameter>

Then add this line before writing to the log: MDC.Set("machine", Environment.MachineName);