public static string AddPIDAndAppDomainNameToFileName(string file)
{
// any supplied PID would be useless since we always append the PID
var fileName = Path.GetFileName(file).Replace("PID", "");
var idx = fileName.LastIndexOf('.');
if (idx == -1)
{
idx = fileName.Length;
}
var strippedAppDomainName = AppDomain.CurrentDomain.FriendlyName.Replace('.', '_');
strippedAppDomainName = strippedAppDomainName.Replace(':', '_').Replace('\\', '_').Replace('/', '_');
var pidAndAppDomainName = "_" + Process.GetCurrentProcess().Id + "_" + strippedAppDomainName;
// insert process id and AppDomain name
fileName = fileName.Insert(idx, pidAndAppDomainName);
return Path.Combine(Path.GetDirectoryName(file), fileName);
}
}