This is my configuration for log4net:
<log4net> <appender name="MyLogger" type="log4net.Appender.RollingFileAppender"> <file value="MyLog.log" /> <appendToFile value="true" /> <rollingStyle value="Size"/> <maxSizeRollBackups value="20"/> <maximumFileSize value="1000KB"/> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss},%p,%m%n" /> </layout> </appender> <root> <level value="DEBUG" /> <appender-ref ref="MyLogger" /> </root> </log4net>
In C# I'm trying to get the name of the log file (which is MyLog.log). I googled and tried many things but failed to do so. Any help?
Thanks!
In your case, the log file will be in bin\Debug\netcoreapp3.
You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation.
You can download the desired Log4net. dll from this path: http://logging.apache.org/log4net/download.html, Whilst I've also attached the required Log4net.
Log4net watches for any new file created in the folder so simply creating the . log4net configuration file triggers the update within the component that is logging. When using a file appender, the destination folder does not have to exist. Log4net creates the folder.
Solution is quite easy in your situation; just use this code:
var rootAppender = ((Hierarchy)LogManager.GetRepository()) .Root.Appenders.OfType<FileAppender>() .FirstOrDefault(); string filename = rootAppender != null ? rootAppender.File : string.Empty;
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