diff --git a/source/CaddyLog-To-AccessLog.ps1 b/source/CaddyLog-To-AccessLog.ps1 index a720967..7d5f716 100644 --- a/source/CaddyLog-To-AccessLog.ps1 +++ b/source/CaddyLog-To-AccessLog.ps1 @@ -25,46 +25,32 @@ Get-Content -Tail $lines -Wait -Path $inFile | ForEach-Object { $userAgent = $r.headers.'User-Agent' | Select-Object -First 1 $referer = $r.headers.Referer | Select-Object -First 1 - $null = $builder.Clear() - $null = $builder.Append($r.remote_ip) - $null = $builder.Append(" - [") - $null = $builder.Append($baseDate.AddSeconds($l.ts).ToString("yyyy-MM-dd HH:mm:ss.fff")) - $null = $builder.Append("] """) - $null = $builder.Append($r.host) - $null = $builder.Append(""" ") - $null = $builder.Append($r.method) - $null = $builder.Append(" ") - $null = $builder.Append($r.uri) - $null = $builder.Append(" ") - $null = $builder.Append($r.proto) - $null = $builder.Append(" ") - $null = $builder.Append($l.status) - $null = $builder.Append(" ") - $null = $builder.Append($l.size) - $null = $builder.Append(" """) - $null = $builder.Append($referer) - $null = $builder.Append(""" """) - $null = $builder.Append($userAgent) - $null = $builder.Append("""") - - $commonLog = $builder.ToString() + $commonLog = $builder + .Clear() + .Append($r.remote_ip) + .Append(" - [") + .Append($baseDate.AddSeconds($l.ts).ToString("yyyy-MM-dd HH:mm:ss.fff")) + .Append("] """) + .Append($r.host) + .Append(""" ") + .Append($r.method) + .Append(" ") + .Append($r.uri) + .Append(" ") + .Append($r.proto) + .Append(" ") + .Append($l.status) + .Append(" ") + .Append($l.size) + .Append(" """) + .Append($referer) + .Append(""" """) + .Append($userAgent) + .Append("""") + .ToString() Write-Output $commonLog $outputWriter.WriteLine($commonLog) $outputWriter.Flush() - - #[system.string]::Join( - # " ", - # @( - # "$($r.remote_ip) - [$($baseDate.AddSeconds($l.ts).ToString("yyyy-MM-dd HH:mm:ss.fff"))]", - # """$($r.host)""", - # $r.method, - # $r.uri, - # $r.proto, - # $l.status, - # $l.size, - # """$($r.headers.Referer)""", - # """$ua""" - # )) }