Skip to content
Snippets Groups Projects
Commit dfbac75c authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Move log files to "var/" subdir and include hostname in file name

Fixes #5
parent 231d684c
No related branches found
No related tags found
No related merge requests found
......@@ -157,9 +157,9 @@ namespace ATxService
var logConfig = new LoggingConfiguration();
var fileTarget = new FileTarget {
Name = "file",
FileName = ServiceName + ".log",
FileName = $"var/{ServiceName}.{Environment.MachineName}.log",
ArchiveAboveSize = 1 * Conv.MegaBytes,
ArchiveFileName = ServiceName + ".{#}.log",
ArchiveFileName = $"var/{ServiceName}.{Environment.MachineName}" + ".{#}.log",
MaxArchiveFiles = 9,
KeepFileOpen = true,
Layout = LogFormatDefault,
......
......@@ -21,7 +21,10 @@ namespace ATxService
}
catch (Exception ex)
{
var startupLog = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "startup.log");
var startupLog = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"var",
"startup.log");
using (var sw = File.AppendText(startupLog))
{
sw.WriteLine(ex.Message);
......
......@@ -6,7 +6,7 @@ if (Test-Path $LocalConfiguration) {
Exit
}
$LogFile = $ServiceDir + "\AutoTx.log"
$LogFile = "$($ServiceDir)\var\$($ServiceName).$($env:COMPUTERNAME).log"
if (Test-Path $LogFile) {
Write-Host "Watching logfile '$LogFile':"
......
......@@ -159,7 +159,7 @@ function Start-MyService {
$ex = $_.Exception.Message
$msg = "Trying to start the service results in this error:`n$($ex)`n`n"
$msg += " -------------------- last 50 log lines --------------------`n"
$msg += Get-LastLogLines "$($LogFile)" 50
$msg += Get-LastLogLines "$($LogFilePfx).log" 50
$msg += " -------------------- ----------------- --------------------`n"
Send-MailReport -Subject "Startup of service $($ServiceName) failed!" `
-Body $msg
......@@ -450,16 +450,12 @@ function ServiceUpdate-Requested {
function Upload-LogFiles {
$Dest = "$($UploadPathLogs)\$($env:COMPUTERNAME)"
New-Item -Force -Type Directory $Dest | Out-Null
try {
Copy-Item -Force -ErrorAction Stop `
-Path "$($LogFile)" `
-Destination $Dest
Log-Debug "Uploaded logfile to [$($Dest)]."
Copy-Item -Force -Path "$($LogFilePfx)*.log" -Destination $UploadPathLogs
Log-Debug "Uploaded logfile(s) to [$($UploadPathLogs)]."
}
catch {
Log-Warning "Uploading logfile FAILED!`n$($_.Exception.Message)"
Log-Warning "Uploading logfile(s) FAILED!`n$($_.Exception.Message)"
}
}
......@@ -589,8 +585,8 @@ Log-Debug "$($Me) started..."
$ServiceRunningBefore = ServiceIsRunning $ServiceName
$ConfigPath = "$($InstallationPath)\conf"
$LogPath = "$($InstallationPath)"
$LogFile = "$($LogPath)\AutoTx.log"
$LogPath = "$($InstallationPath)\var"
$LogFilePfx = "$($LogPath)\$($ServiceName).$($env:COMPUTERNAME)"
$StatusXml = "$($InstallationPath)\var\status.xml"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment