Support an optionally specified logpath element.

git-svn-id: https://svn.kenai.com/svn/winsw~subversion/trunk@11 c8b2a3fe-9b5b-6a51-a37e-dc31b0e308fa
remotes/git-svn
jjasper4 2008-11-08 22:02:48 +00:00
parent bd2ce3688a
commit e5b221f801
1 changed files with 33 additions and 5 deletions

38
Main.cs
View File

@ -24,6 +24,7 @@ namespace winsw
/// Where did we find the configuration file? /// Where did we find the configuration file?
/// </summary> /// </summary>
public readonly string BasePath; public readonly string BasePath;
public readonly string BaseName;
public static string ExecutablePath public static string ExecutablePath
{ {
@ -54,7 +55,8 @@ namespace winsw
// register the base directory as environment variable so that future expansions can refer to this. // register the base directory as environment variable so that future expansions can refer to this.
Environment.SetEnvironmentVariable("BASE", p); Environment.SetEnvironmentVariable("BASE", p);
BasePath = Path.Combine(p, baseName); BaseName = baseName;
BasePath = Path.Combine(p, BaseName);
dom.Load(BasePath+".xml"); dom.Load(BasePath+".xml");
} }
@ -104,6 +106,26 @@ namespace winsw
} }
} }
/// <summary>
/// LogDirectory is the service wrapper executable directory or the optionally specified logpath element.
/// </summary>
public string LogDirectory
{
get
{
XmlNode loggingNode = dom.SelectSingleNode("//logpath");
string logDirectory = Path.GetDirectoryName(ExecutablePath);
if (loggingNode != null)
{
logDirectory = loggingNode.InnerText;
}
return logDirectory;
}
}
/// <summary> /// <summary>
/// Logmode to 'reset', 'roll' once or 'append' [default] the out.log and err.log files. /// Logmode to 'reset', 'roll' once or 'append' [default] the out.log and err.log files.
/// </summary> /// </summary>
@ -271,9 +293,16 @@ namespace winsw
/// </summary> /// </summary>
private void HandleLogfiles() private void HandleLogfiles()
{ {
string baseName = descriptor.BasePath; string logDirectory = descriptor.LogDirectory;
string errorLogfilename = baseName + ".err.log";
string outputLogfilename = baseName + ".out.log"; if (!Directory.Exists(logDirectory))
{
Directory.CreateDirectory(logDirectory);
}
string baseName = descriptor.BaseName;
string errorLogfilename = Path.Combine(logDirectory, baseName + ".err.log");
string outputLogfilename = Path.Combine(logDirectory, baseName + ".out.log");
System.IO.FileMode fileMode = FileMode.Append; System.IO.FileMode fileMode = FileMode.Append;
@ -302,7 +331,6 @@ namespace winsw
HandleFileCopies(); HandleFileCopies();
EventLog.WriteEntry("Starting "+descriptor.Executable+' '+descriptor.Arguments); EventLog.WriteEntry("Starting "+descriptor.Executable+' '+descriptor.Arguments);
string baseName = descriptor.BasePath;
var ps = process.StartInfo; var ps = process.StartInfo;
ps.FileName = descriptor.Executable; ps.FileName = descriptor.Executable;