Autofac.Extras.NLog | Autofac module to integrate Autofac | Dependency Injection library
kandi X-RAY | Autofac.Extras.NLog Summary
kandi X-RAY | Autofac.Extras.NLog Summary
An Autofac module to integrate Autofac and NLog, it supports both constructor and property injection.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Autofac.Extras.NLog
Autofac.Extras.NLog Key Features
Autofac.Extras.NLog Examples and Code Snippets
containerBuilder.RegisterModule();
public class SampleClassWithConstructorDependency : ISampleInterface
{
private readonly ILogger _logger;
public SampleClassWithConstructorDependency(ILogger logger)
{
_logger = logger;
}
containerBuilder.RegisterModule();
Community Discussions
Trending Discussions on Autofac.Extras.NLog
QUESTION
I have a C# Program running as a Windows service doing some Network shenanigans I thought I had last-ditch "Log Fatal Errors" handling set up. But I've come across an edge case where the Service ends up dead but dodges those catches. :(
I believe this is caused by code throwing an Exception in the EventHandler registered to a .NET library's event.
Obviously I can (andshould!) catch the Exception in my handler, but I'd like to understand how this is avoiding my fall-back error handling, and whether I can add some even more robust fall back logging, to ensure that I have some log records to analyse similar silent bugs in future.
The punchline of relevant code isn't terribly complex:ServiceBase.Run(container.Resolve());
in a try ...catch
in Program.Main()
MyProjectWindowsService : ServiceBase
is the service object with an OnStop()
implmentation.
NetworkChange.NetworkAvailabilityChanged += CodeThatThrows;
But when that Exception is thrown, neither OnStop()
nor the try...catch
trigger.
I can get it in a debugger, and it doesn't seem to go anywhere .. it just ... stops.
Fuller program details below, if you want them.
How can I catch and log unhandled exceptions in Event Handlers registered to external library events?
(Also ... Is the behaviour I've described above the expected behaviour, or is there something slightly weird happening?)
Program EXE entry point: ...ANSWER
Answered 2019-Dec-10 at 11:49I unfortunately can only speculate why the exception isn't being caught by your code (and I've kept that speculation to the comments)
However 2 events that might help you are,
AppDomain.UnhandledException - this allows you to register a global handler for any unhandled exceptions in your application. Here is the documentation https://docs.microsoft.com/en-us/dotnet/api/system.appdomain.unhandledexception?view=netframework-4.8
TaskScheduler.UnobservedTaskException - I've included this as I'm not familiar with the internals of the framework libraries you are using, but there maybe some asynchronous code happening somewhere, that is potentially not observing the result of a task. If a faulted task (ie an exception was thrown) is never awaited or never has the Result property accessed and then goes out of scope so it can be garbage collected; at some indeterminate point in the future, it will get collected and an UnobservedTaskException will get thrown. Subscribing to this event, will let you handle that scenario. Documentation here
QUESTION
I'm using Autofac to DI and MVVM. I have a global service registered as such:
...ANSWER
Answered 2017-Jul-14 at 17:09Property Injection does not work out-of-the-box, you need to set up class you want to use property injection in, so
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Autofac.Extras.NLog
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page