I am using Log4Net
to log an exception in my .Net Windows service
application.
I want to mention that, my windows service application is running with multi-threading execution
, which means that
each task is being processed on each different thread and I have used Delegate - (BeginInvoke)
pattern.
Importantly, I am using dynamic properties
to generate multiple log files dynamically with Log4Net
based on application's different scenarios.
Now, on every logging/ exception
scenarios (in C# method), I have used Logger.Log
method to log the info/ exception with Log4Net
.
Code (Dynamic file generation)
GlobalContext.Properties[FileNameParameter] = DirectoryName + fileName;
LogManager.Info(logMessage);
Config Settings
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="D:\Data\%property{FileName}_info.log"/>
</appender>
The problem is (I believe), due to multi-threaded code execution, I am getting following things with Log4Net which is weird.
- Sometime log file generates, but NO message content.
- Sometime file itself not generating.
- Sometime few file generates, few are NOT generating.
Would you please do let me know why Log4Net behaves like this. I need stable logging with multi-threading code execution.
Thanks in advance!