-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add variable hostname to $logMessage #110
Comments
Hi @kilale, thank you for your feedback, really appreciated. Personally I don't agree on adding a system call every time you produce a log record and it's not inherent to the log. Try this (inside the calling script): $HostName = [System.Net.Dns]::GetHostName()
Add-LoggingTarget -Name File -Configuration @{
Level = $LogLevel
Path = "${LogPath}\%{+%Y%m%d}_${Name}.log"
Format = "[%{timestamp:+yyyy-MM-dd HH:mm:ss.fff}] ${HostName} %{message}"
} |
Hi @EsOsO, |
Maybe you need to pass it as variable during Target configuration. Provide me an example, if you can |
The vRLI target configuration is similar to Teams Name = 'vRLI'
Configuration = @{
LogInsightServer = @{Required = $true; Type = [string]; Default = $null }
Details = @{Required = $false; Type = [bool]; Default = $true}
Level = @{Required = $false; Type = [string]; Default = $Logging.Level }
} The payload will be build in the Logger: $payload = @{
messages = ([Object[]]([ordered]@{
text = $Log.message
timestamp = $Log.timestamp
fields = if ($Configuration.Details) {
$Log.Keys | Where-Object {
$_ -notin 'message', 'timestamp'
} | sort | ForEach-Object {
[ordered] @{
name = $_
content = if ([string]::IsNullOrEmpty($Log[$_])) {
'(none)'
} else {
[string] $Log[$_]
}
}
}
} else {
[Object[]]$fields
}
}))
} | convertto-json -depth 5 Which is then invoked as REST call. "fields" contains all custom fields. Target is added like this: Add-LoggingTarget -Name vRLI -Configuration @{
LogInsightServer = $vrliserver
Level = $LogLevel
Details = $true
} Similar to the Teams target, which additionally contains the custom definition of colors. |
Take a look at the ElasticSearch target Flatten variable, maybe is what you need. I don't get your needs, sorry. You want to call |
Hi,
I really like this module. I noticed, that a field "hostname" is missing in $logMessage.
Made a fork for my implementation, which currently has this change.
File: public/Write-Log.ps1
$logMessage = [hashtable] @{ hostname = [System.Net.Dns]::GetHostName() ... }
Would love to see this change in an upcoming release or the option to define custom fields for the $logMessage details.
Thanks!
The text was updated successfully, but these errors were encountered: