Consolidate StringBuilder method calls. Remove commented code.

This commit is contained in:
Steve Dinn 2023-12-07 01:06:09 +00:00
parent 6804e1af58
commit db1503fc3b

View file

@ -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"""
# ))
}