LoggerRemoveLogs Method

Removes the oldest non-read-only log files in a directory.

Definition

Namespace: Logging.Helper
Assembly: Logging.Helper (in Logging.Helper.dll) Version: 2.0.6
C#
public bool RemoveLogs(
	string directory,
	string logNameMask,
	int maxFiles = 0
)

Parameters

directory  String
Directory containing the log files.
logNameMask  String
Search pattern in the form [LogFile]*.[ext] of the log file names.
maxFiles  Int32  (Optional)
Maximum number of log files to keep.

Return Value

Boolean
if any log files have been removed, otherwise is returned.

Example

In a method that needs to remove old log files:
C#
var directory = @"C:\Temp\Logs" );
const string mask = "LogfileName*.log";
const int maxLogFiles = 50;
logging.RemoveLogs( directory, mask, maxLogFiles );

Exceptions

ArgumentExceptionThrown when one of the arguments provided to a method is not valid.
IOExceptionThrown when an I/O error occurs.
SecurityExceptionThrown when a security error is detected.
UnauthorizedAccessExceptionThrown when the operating system denies access because of an I/O error or a specific type of security error.

See Also