protected virtual string DetermineFilePath(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
filePath = string.Empty;
}
if (filePath.Contains(AutoLogFileName))
{
filePath = filePath.Replace(AutoLogFileName, AutoLogFileNameReplacement);
}
var isWebApp = HttpContextHelper.HasHttpContext();
string dataDirectory;
if (_assembly != null)
{
dataDirectory = isWebApp ? IO.Path.GetApplicationDataDirectoryForAllUsers(_assembly.Company(), _assembly.Product())
: IO.Path.GetApplicationDataDirectory(_assembly.Company(), _assembly.Product());
}
else
{
dataDirectory = isWebApp ? IO.Path.GetApplicationDataDirectoryForAllUsers()
: IO.Path.GetApplicationDataDirectory();
}
if (filePath.Contains(AssemblyName))
{
filePath = filePath.Replace(AssemblyName, _assembly.GetName().Name);
}
if (filePath.Contains(AssemblyProduct))
{
filePath = filePath.Replace(AssemblyProduct, _assembly.Product());
}
if (filePath.Contains(AssemblyCompany))
{
filePath = filePath.Replace(AssemblyCompany, _assembly.Company());
}
if (filePath.Contains(ProcessId))
{
filePath = filePath.Replace(ProcessId, Process.GetCurrentProcess().Id.ToString());
}
if (filePath.Contains(Date))
{
filePath = filePath.Replace(Date, DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
}
if (filePath.Contains(Time))
{
filePath = filePath.Replace(Time, DateTime.Now.ToString("HHmmss", CultureInfo.InvariantCulture));
}
if (filePath.Contains(AppData))
{
filePath = filePath.Replace(AppData, dataDirectory);
}
if (filePath.Contains(AppDataLocal))
{
var dataDirectoryLocal = _assembly != null ? IO.Path.GetApplicationDataDirectory(ApplicationDataTarget.UserLocal,
_assembly.Company(),
_assembly.Product())
: IO.Path.GetApplicationDataDirectory(ApplicationDataTarget.UserLocal);
filePath = filePath.Replace(AppDataLocal, dataDirectoryLocal);
}
if (filePath.Contains(AppDataRoaming))
{
var dataDirectoryRoaming = _assembly != null ? IO.Path.GetApplicationDataDirectory(ApplicationDataTarget.UserRoaming,
_assembly.Company(),
_assembly.Product())
: IO.Path.GetApplicationDataDirectory(ApplicationDataTarget.UserRoaming);
filePath = filePath.Replace(AppDataRoaming, dataDirectoryRoaming);
}
if (filePath.Contains(AppDataMachine))
{
var dataDirectoryMachine = _assembly != null ? IO.Path.GetApplicationDataDirectory(ApplicationDataTarget.Machine,
_assembly.Company(),
_assembly.Product())
: IO.Path.GetApplicationDataDirectory(ApplicationDataTarget.Machine);
filePath = filePath.Replace(AppDataMachine, dataDirectoryMachine);
}
if (filePath.Contains(AppDir))
{
filePath = filePath.Replace(AppDir, AppDomain.CurrentDomain.BaseDirectory);
}
filePath = IO.Path.GetFullPath(filePath, dataDirectory);
if (!filePath.EndsWith(".log"))
{
filePath += ".log";
}
return filePath;
}