I want to use LogicalThreadContext to pass some context information in my WCF service. I need to pass different properties. In C #, I have code
LogicalThreadContext.Properties["MyProperty"] = 1;
In log4net configuration 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 the magazine I got
2015-11-03 16:24:36,313 [10] [{MyProperty=1, log4net:Identity=, log4net:UserName=User, log4net:HostName=User}] INFO - Info
I do not want to have the system properties log4net: Identity, log4net: UserName and log4net: HostName in the log. How to do it? I can write config as follows
conversionPattern value="%d [%2t] [%property{MyProperty}] %level %m%n"
But I have several properties in the code, and I want to see only the properties that I added. Code
LogicalThreadContext.Properties.Remove("log4net:UserName");
does not work.
source share