Last active
October 27, 2017 07:44
-
-
Save arbing/dbec31e692a7d03bb9a0257d7d362440 to your computer and use it in GitHub Desktop.
Log4Net生成空日志文件的解决方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// https://stackoverflow.com/questions/2533403/how-to-disable-creation-of-empty-log-file-on-app-start | |
using log4net.Appender; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
namespace DebugLog | |
{ | |
public class MinimalLockDeleteEmpty : FileAppender.MinimalLock | |
{ | |
public override void ReleaseLock() | |
{ | |
base.ReleaseLock(); | |
var logFile = new FileInfo(CurrentAppender.File); | |
if (logFile.Exists && logFile.Length <= 0) | |
{ | |
logFile.Delete(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment