Ensure safe app start in case server dns problem exception is thrown#86
Ensure safe app start in case server dns problem exception is thrown#86grendizeras wants to merge 2 commits intomattwcole:devfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prevents application crashes during startup when DNS resolution fails for the GELF logging server. The changes wrap the logger initialization in a try-catch block and return a NullLogger when the message processor fails to initialize, allowing the application to start even if the logging endpoint is unavailable.
Key Changes:
- Added defensive null check in
CreateLoggerto returnNullLogger.Instancewhen message processor initialization fails - Wrapped
LoadLoggerOptionslogic in try-catch to prevent DNS exceptions from propagating to application startup - Reordered using statements for consistency
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| catch (Exception ex) | ||
| { | ||
| logger.Value.Options = options; | ||
| Console.WriteLine(ex.ToString()); |
There was a problem hiding this comment.
The exception is being caught and silently swallowed with only a console output. This could make debugging difficult in production. Consider at minimum adding a comment explaining why exceptions are suppressed and that logging will degrade to NullLogger, or providing a more robust error handling strategy.
| Console.WriteLine(ex.ToString()); | |
| // Swallowing exceptions here is intentional: failing to initialize or reload GELF | |
| // logging options should not crash the application or configuration reload. | |
| // If initialization never succeeds, _messageProcessor will remain null and | |
| // CreateLogger will fall back to NullLogger.Instance, effectively disabling GELF logging. | |
| // The exception details are written to the console to aid diagnostics. | |
| Console.Error.WriteLine($"[GelfLoggerProvider] Failed to load GELF logger options: {ex}"); |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
When using gelf with server dns endpoint, if dns fails, application fails to start as Exception propagates to application startup, causing app to crash.