mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Bug: Example for WireMock as Windows Service throws Exception because of WireMockConsoleLogger #151
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @paulssn on GitHub (Nov 6, 2018).
Originally assigned to: @paulssn on GitHub.
Problem:
If I run the example for WireMock as a Windows Service, it throws the following exception on service startup:
Reason:
This is caused by the
WireMockConsoleLoggerwhich is also used if the application is actually running as a service. In this case the exception is thrown when the logger tries to access the console (which is actually not accessible in the service context).Possible solution:
Use the
WireMockConsoleLoggeronly in case the application is running as console app and use theWireMockNullLoggerif it's running as service.Of course, this can be easily fixed and does therefore not present a major problem, but it would be nice if the example would just work out of the box without the need to fix this.
@paulssn commented on GitHub (Nov 6, 2018):
I'd be happy to submit a PR, if that's ok for you.
@StefH commented on GitHub (Nov 6, 2018):
Thanks for finding this bug.
You can submit a PR where you just use the
WireMockNullLoggerin the Program.cs.Or maybe better (however more work), create
WireMockEventLoggerwhich logs to the Windows Event log ? (Maybe using log4net / nlog or ... ?)@paulssn commented on GitHub (Nov 6, 2018):
You're welcome. Thank you for maintaining this useful project!
For now I fixed it by using the
WireMockNullLoggerin the corresponding case.I agree with you that using an actual logger would be better and make sense. I'll consider to implement it and submit a separate PR for it as well.
Where would you put the corresponding logger? Just in the
WireMock.Net.Service-project like for example theWireMockLog4NetLoggerwhich lives in theWireMock.Net.StandAlone.NETCoreApp-example?I'd tend to use a log4net-logger and configure something like an EventLogAppender and maybe an additional file appender. Would this basically match your thoughts?
@StefH commented on GitHub (Nov 6, 2018):
Correct. Just add a new WireMockEventLogger in the WireMock.Net.Service-project which can be based on log4net or just custom code to write to event log.