I am using %property% to set the output file path in the Log4Net configuration file. A log file will be created in the APP data folder every time when the application launches. I am using the Composite rolling style for rolling the files.
But now my requirement is to roll/change the file path based on some user interactions in the application. How can I achieve this, can anyone suggest me to achieve this.
Please let me know if my requirement is not clear.
Thanks.
You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation.
RollingFileAppender can roll log files based on size or date or both depending on the setting of the RollingStyle property. When set to Size the log file will be rolled once its size exceeds the MaximumFileSize.
You have 2 questions:
code:
LogManager.GetRepository().GetAppenders();
config:
<appender name="YourAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="~/App_Data/%property{LogName}" />
</appender>
Important is the type="log4net.Util.PatternString"
. Set the property before initializing log4net.
log4net.GlobalContext.Properties["LogName"] = name;
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