logging-log4net-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike" <mstanco...@oztralia.com>
Subject Using Environment variables in the FileAppender.File property.
Date Wed, 08 Dec 2004 02:22:22 GMT
Hi All,

I've been using log4net on an xp platform, and I wanted each users log file
to go into their separate user folders.  To achieve this, I've changed the
FileAppender.ConvertToFullPath method as follows.

protected static string ConvertToFullPath(string path)
{
	if (path == null)
	{
		throw new ArgumentNullException("path");
	}

	string expandedPath = Environment.ExpandEnvironmentVariables(path);

	if (SystemInfo.ApplicationBaseDirectory != null)
	{
		// Note that Path.Combine will return the second path if it is rooted
		return Path.GetFullPath(
			Path.Combine(SystemInfo.ApplicationBaseDirectory, expandedPath));
	}
	return Path.GetFullPath(expandedPath);
}

Pretty much the same as how it was, just expanded the env variables between
getting the full path.  This way the file '%USERPROFILE%\mylog.txt' will go
into the user folder.  Is this something that would be useful for others, or
is this functionality already present somewhere, and I've overlooked it?

Cheers -Mike

"The pure and simple truth is rarely pure and never simple."
Oscar Wilde


Mime
View raw message