Skip to content

Instantly share code, notes, and snippets.

@arbing
Last active October 27, 2017 07:44
Show Gist options
  • Save arbing/dbec31e692a7d03bb9a0257d7d362440 to your computer and use it in GitHub Desktop.
Save arbing/dbec31e692a7d03bb9a0257d7d362440 to your computer and use it in GitHub Desktop.
Log4Net生成空日志文件的解决方法
/// 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