Docker Community Forums

Share and learn in the Docker community.

Is there a way to log to the host eventlog


(Sfought) #1

Our existing ASP/MVC apps all log to the eventlog. I’m working on moving an app into docker, but I need the events from the container’s eventlog to make it to the host’s eventlog. Is this possible?


(Sfought) #2

I didn’t get an answer from anyone, but I did find what I was looking for in the Docker for Windows book. I have a startup powershell script that starts W3SVC and then a loop that polls the eventlog and writes it out to stdout where it can be pulled using docker container logs. It also configures IIS to log to C:\Logs which I have setup as a volume on the host, so I can monitor the IIS logs. Here’s what it looks like:

Configure IIS to log to c:\logs which is mapped to c:\logs on the host, and start IIS

Import-Module WebAdministration
Set-WebConfigurationProperty -pspath ‘MACHINE/WEBROOT/APPHOST’ -filter “system.applicationHost/sites/siteDefaults/logFile” -name “directory” -value “c:\logs”
Start-Service W3SVC

Poll eventlog and write entries to stdout so they can be retrieved with docker log

$lastCheck = (Get-Date).AddSeconds(-5)
while ($true)
{
Get-EventLog -LogName Application -After $lastCheck | Select-Object EntryType, TimeGenerated, Source, Message
$lastCheck = Get-Date
Start-Sleep -Seconds 5
}