Are you wanting to store what is in the existing IQService logs? Or different information that would be in an After Create/Modify PowerShell script?
If using the connector rules, there are examples here which include logging
If wanting to manipulate the existing log files, you could have a scheduled task that calls a PowerShell script to read the files and organize/manage them how you would like.
Ask is not related to native rule. I am asking about iqservice logs which is stored in IQTrace.
Currently all logs gets appended in IQTrace.log file. I want it be to be something like this based on date or size it creates a new file.
IQTrcce-01.log
IQTrcce-02.log
IQTrcce-03.log
IQTrcce-04.log
Have already checked this document, but it don’t help my requirement.
My requirement is:
Currently all logs gets appended in IQTrace.log file. I want it be to be something like this based on date or size it creates a new file.
IQTrcce-01.log
IQTrcce-02.log
IQTrcce-03.log
IQTrcce-04.log
In this scenario you have to leverage scheduled AD Task that will invoke a custom log management PSScript which will check the last modified metadata of IQService log and move them to a zipped state in a specific location.
You can use below sample PowerShell script and schedule it to run on regular interval and archive the file if it has reached a certain limit. Feel free to make changes in the snippet as per your use-case.
# Define variables
$logFilePath = "C:\Path\To\Your\logfile.log"
$archiveFolder = "C:\Path\To\Your\ArchiveFolder"
$maxFileSizeMB = 10
# Convert max file size to bytes
$maxFileSizeBytes = $maxFileSizeMB * 1MB
# Check if the log file exists
if (Test-Path $logFilePath) {
# Get the file info
$fileInfo = Get-Item $logFilePath
# Check the file size
if ($fileInfo.Length -gt $maxFileSizeBytes) {
# Create archive folder if it doesn't exist
if (-not (Test-Path $archiveFolder)) {
New-Item -ItemType Directory -Path $archiveFolder
}
# Generate a timestamp
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
# Define the archive file name
$archiveFileName = "$($fileInfo.BaseName)_$timestamp$($fileInfo.Extension)"
$archiveFilePath = Join-Path -Path $archiveFolder -ChildPath $archiveFileName
# Move the log file to the archive location
Move-Item -Path $logFilePath -Destination $archiveFilePath
# Create a new, empty log file
New-Item -ItemType File -Path $logFilePath
}
}
else {
Write-Host "Log file does not exist."
}