I recently added log4net logging to this website. After configuring log4net and adding logging code the the web application, I immediately added a page to my administration site to display the log. Unfortunately, the initial code I wrote threw an exception because, not surprisingly, the log4net log file was locked.
The trick is to open the file in FileShare.ReadWrite mode:
... protected string logFileText; protected void Page_Load(object sender, EventArgs e) { string path = Server.MapPath("~/logs/log.txt"); using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (StreamReader streamReader = new StreamReader(fileStream)) { logFileText = streamReader.ReadToEnd(); } } ...
Name | Comment | URL | Date/Time |
Linus | The solution provided by Sunil is not the same and will not solve the same issues, as "MinimalLock" can still lock the file, as I already had that set and needed to stream. | December 19, 2014 | |
Sunil Sharma | I found a better method to do this at: http://hoenes.blogspot.com/2006/08/displaying-log4net-log-file-on-aspnet.html | http://hoenes.blogspot.com/2006/08/displaying-log4net-log-file-on-aspnet.html | February 18, 2009 |
mr mO | Thank you sooo very much! | http://mokhan.ca | July 24, 2008 |
Title | Date |
EBTCalc (Android) Version 1.53 is now available | May 19, 2024 |
Vault 3 Security Enhancements | October 24, 2023 |
Vault 3 is now available for Apple OSX M2 Mac Computers! | September 18, 2023 |
Vault (for Desktop) Version 0.77 Released | March 26, 2023 |
EBTCalc (Android) Version 1.44 is now available | October 12, 2021 |
Vault (Desktop) Version 0.72 Released | October 6, 2021 |
EBT Compass is Now Available for Android Devices | June 2, 2021 |