This is a RabbitMQ-based pub/sub logging library for C#.NET, with a PowerShell module wrapper. It includes:
- Logging class library for C#
- PowerShell module wrapper, for making logging from PS scripts easy
- Real-time watcher console application
- Windows service that writes all log messages to a SQL database. Uses Entity Framework.
I have various scripts and services that perform automated tasks or need to be monitored. These are distributed across different machines and therefore it is tedious and impractical to access log files for a quick status check. Using messaging queues, we can easily monitor as much or as little of the published log messages as we want. Since multiple queues can be set up on an exchange, we can have multiple listeners, for example: a real-time viewer, a database writer, and a file writer.
- A RabbitMQ service
- SQL Server, if you want to store the messages in a database
Note: There is an optional parameter to install it in the current user's directory instead of in Program Files (shared location). Just add $true as a parameter.
.\BuildAndInstallPowerShellModule.ps1
- Build the solution
- Create an empty database and a user with dbo membership
- Copy App.config.example to RabbitMqLogger.DatabaseWriter\bin\Debug and rename it to RabbitMqLogger.DatabaseWriter.exe.config
- Add your connection string and RabbitMQ host name to the config file
- Open Developer Command Prompt for VS2015 as an Administrator
- cd to RabbitMqLogger.DatabaseWriter\bin\Debug
- Run: installutil RabbitMqLogger.DatabaseWriter.exe
- Start the service in the Services console
(RabbitMQ running on rabbit.local)
Import-Module RabbitMqLogger
New-RmqLogger rabbit.local
Write-InfoRmqLog "Test logging"
Write-ErrorRmqLog "Bad issue occurred" $rmq.JobStart "Bootstrapping" "FileNotFoundException: C:\Goofy.gif"
- New-RmqLogger
- Write-DebugRmqLog
- Write-InfoRmqLog
- Write-WarnRmqLog
- Write-ErrorRmqLog
- Write-FatalRmqLog