I want to use LogicalThreadContext to pass some context information in my WCF service. I need to pass different properties. In C# I has code
LogicalThreadContext.Properties["MyProperty"] = 1;
In log4net config I have
<log4net>
<appender name="RollingLogFileAppenderSize" type="log4net.Appender.RollingFileAppender">
<file value="Logs\Log.log" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value="yyyyMMdd" />
<maxSizeRollBackups value="3" />
<maximumFileSize value="5MB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%2t] [%property] %level %m%n" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="RollingLogFileAppenderSize" />
</root>
</log4net>
And in log I got
2015-11-03 16:24:36,313 [10] [{MyProperty=1, log4net:Identity=, log4net:UserName=User, log4net:HostName=User}] INFO - Info
I don't want to have system properties log4net:Identity, log4net:UserName and log4net:HostName in log. How to do this? I can write config like this
conversionPattern value="%d [%2t] [%property{MyProperty}] %level %m%n"
But I have several properties in code and I want to see only properties that I added. Code
LogicalThreadContext.Properties.Remove("log4net:UserName");
doesn't work.
How do I completely disable all logging at runtime? Setting the Threshold on the Hierarchy to Level OFF will disable all logging from that Hierarchy. This can be done in the log4net configuration file by setting the "threshold" attribute on the log4net configuration element to "OFF".
You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation.
log4net is a port of the excellent Apache log4j™ framework to the Microsoft® . NET runtime. We have kept the framework similar in spirit to the original log4j while taking advantage of new features in the . NET runtime.
Is log4net thread-safe? Yes, log4net is thread-safe. So, no need for manual locking.
I found that it's posible to remove only log4net:HostName property with code
GlobalContext.Properties.Remove(LoggingEvent.HostNameProperty)
.
log4net:Identity and log4net:UserName cannot be removed because of CreateCompositeProperties
method in log4net.Core.LoggingEvent
class https://github.com/apache/log4net/blob/trunk/src/Core/LoggingEvent.cs.
It adds these properties without any conditions and so it's imposible to remove them for the last log4net version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With