Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
If you work with legacy apps (or maybe some not so legacy apps) in containers then you know about what a pain it is to read the all important event log. In this post I'll present a passable pattern that is good enough for occasional use, like when initially deploying or diagnosing an in-production failure.
Right up front: This is not ideal but it's not bad and it works. It's WAY better than viewing events in the Container CLI like I presented in here. If anybody knows how to remote the EventLog viewer right into the container please let me know and I'll update with credits.
The sequence is:
[on container host]
Open a Powershell sesion
Create a share directory
mkdir c:\shared
Create container with shared volume pointing to the c:\shared directory
docker run -it --name winservcoret2 -v c:\shared:c:\shared microsoft/windowsservercore
Since the container was started with the -it configuration, the PowerShell session will switch to the Container console
[on container]
Do things that create some events, then snap a copy of the event log to a file in the shared volume. In this case we snap the application log but you can snap any log present on the container.
wevtutil epl Application C:\shared\AppLogBackup.evtx
[on container host]
Open c:\shared\AppLogBackup.evtx directly or open it from an existing EventViewer
The Eventlog Viewer will open with the snapped event log
We have a number of options for filtering the events that get written to the .evtx file, for example this script which boxes on start and end dates:
$start = '1/1/2016' $end = '1/2/2017' function GetMilliseconds ($date) { $ts = New-TimeSpan -Start $date -End (Get-Date) [math]::Round($ts.TotalMilliseconds) } # end function $startDate = GetMilliseconds(Get-Date $start) $endDate = GetMilliseconds(Get-Date $end) wevtutil epl Application test.evtx /q:"*[System[TimeCreated[timediff(@SystemTime) >= $endDate] and TimeCreated[timediff(@SystemTime) <= $startDate]]]"
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in