eran-gil / autofac.log4net Goto Github PK
View Code? Open in Web Editor NEWAutofac module for using the log4net logging framework
License: MIT License
Autofac module for using the log4net logging framework
License: MIT License
I got an MVC6 app. Full .NET framework.
Using Autofac and Log4Net (old fashioned, I do like some parts).
Wiring is done based on Quick Start (Without ConfigureContainer) [the other config. is not an option, since due to hangfire.io I need to control the container dispose].
All the log4net references are for the same version.
Use the simple way of module registration.
The Log4Net module is the 1st that got registered.
When I do have a dependency on ILog within any service, it get's nicely resolved.
When I do have an ILog dependency on a controller itself, it won't get resolved.
not working:
controller ctor(Ilog logger) - resolving fails
working:
controller ctor(IService service)
service ctor(ILog logger) - ILog is resolved
InvalidOperationException: Unable to resolve service for type 'log4net.ILog' while attempting to activate 'Project.Web.DiTestL1'. Microsoft.Extensions.Internal.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired) lambda_method(Closure , IServiceProvider , Object[] ) Microsoft.AspNetCore.Mvc.Internal.TypeActivatorCache.CreateInstance(IServiceProvider serviceProvider, Type implementationType) Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerFactory.CreateController(ControllerContext context) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__24.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ExceptionContext context) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__22.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__20.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Builder.RouterMiddleware+d__4.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+d__18.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+d__18.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.VisualStudio.Web.BrowserLink.Runtime.BrowserLinkMiddleware+d__7.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+d__7.MoveNext()
When trying to use this in a solution with Autofac 6. You get the followig error
Method not found: 'Void Autofac.Core.IComponentRegistration.add_Preparing(System.EventHandler`1<Autofac.Core.PreparingEventArgs>)'.
This is due to changes introduced 6.x where IComponentRegistration no longer exposes Preparing, Activating or Activated events.
https://autofaccn.readthedocs.io/en/latest/whats-new/upgradingfrom5to6.html
And hence lines 81 & 83 will not compile when targeting Autofac 6
https://github.com/erangil2/autofac.log4net/blob/master/src/Autofac.log4net/Log4NetModule.cs#L81
hi, I use Class with an ILog Constructor Parameter,my website use mvc5 and netframework4.5.1 .
sometime it works fine. sometimes i got exception. exception message is
{"message": "an error occurred. Exception message: an error occurred while trying to create a controller of type toolservicecontroller. Make sure the controller has a parameterless public constructor. "," exceptiontype ":" system. Invalidoperationexception "," stacktrace ":" in system. Web. Http. Dispatcher. Defaulthttpcontrolleractivator. Create (httprequestmessage request, httprontrollerdescriptor controllerdescriptor, type controllertype) \ R \ Nin system. Web. Http. Controllers. Httpcontrollerdescriptor. Createcontroller (httprequestmessage request) " An error occurred in system. Web. Http. Dispatcher. Httpcontrollerdispatcher. < sendasync > d_uu1. Movenext() "," innerexception ": {" message ":". "," exceptionmessage ":" an exception was thrown while executing a resolve operation. See the innerexception for details. --- > the index exceeds the array limit (see inner exception for details.) "," exceptiontype ":" Autofac. Core. Dependencyresolutionexception "," stacktrace ":" in Autofac. Core. Resolving. Resolveoperation. Execute (icomponentregistration, IEnumerable ` 1 parameters), \ R \ Nin Autofac. Resolutionextensions. Resolveoptionalservice (icomponentcontext context, service, IEnumerable ` 1 Parameters \ R \ Nin system. Web. Http. Dispatcher. Defaulthttpcontrolleractivator. Getinstanceoractivator (httprequestmessage request, type controllertype, func ` 1 & activator), "inner" An error occurred with exception ': {' message ':'. Index,'exceptionmessage ':' is out of array bounds. "," exceptiontype ":" system. Indexoutofrangeexception "," stacktrace ":" in system. Collections. Generic. Dictionary ` 2. Insert (tkey key, tvalue value, Boolean add), \ R \ Nin Autofac. Log4net. Mapping. Cacheddictionaryloggermapper. Getloggername (type), \ R \ Nin Autofac. Log4net. Log4netmodule. Injectloggerproperties (object instance), \ R \ Nin Autofac. Core. R R esolving. Instancelookup. Complete() \ R \ Nin Autofac. Core. Resolving. Resolveoperation. Completeactivations() \ R \ Nin Autofac. Core. Resolving. Resolveoperation. Getorcreateinstance (isharingtimescope currentoperationscope, icomponentregistration, IEnumerable ` 1 parameters) \ R \ Nin Autofac. Core. Resolving. Resolveoperation. Execute (icompo nentRegistration registration, IEnumerable`1 parameters)"}}}
thank you
Can you please provide a GPL-compatible license for this repository.
We ran into a Dictionary corruption issue when running load tests on our product. Based on what I'm seeing, the Dictionaries that are used in the CachedDictionaryLoggerMapper are not thread safe. When one of these dictionaries become corrupted, only seems to happen on high load, we are unable to resolve any services from the container and have to restart the service.
This could be a fairly simple fix. One option would be to swap the Dictionaries out with ConcurrentDictionaries which provide the same functionality but are thread safe.
Exception:
An exception was thrown while executing a resolve operation. See the InnerException for details. Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
StackTrace:
Inner exception System.InvalidOperationException handled at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation:
at System.ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Collections.Generic.Dictionary2.FindValue (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Collections.Generic.Dictionary
2.ContainsKey (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Autofac.log4net.Mapping.CachedDictionaryLoggerMapper.GetLoggerName (Autofac.log4net, Version=6.0.1.0, Culture=neutral, PublicKeyToken=null)
at Autofac.log4net.Log4NetMiddleware.InjectLoggerProperties (Autofac.log4net, Version=6.0.1.0, Culture=neutral, PublicKeyToken=null)
at Autofac.Core.Resolving.Middleware.SharingMiddleware+<>c__DisplayClass5_0.b__0 (Autofac, Version=6.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da)
at Autofac.Core.Lifetime.LifetimeScope.CreateSharedInstance (Autofac, Version=6.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da)
at Autofac.Core.Lifetime.LifetimeScope.CreateSharedInstance (Autofac, Version=6.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da)
at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute (Autofac, Version=6.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da)
at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute (Autofac, Version=6.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da)
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance (Autofac, Version=6.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da)
at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation (Autofac, Version=6.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da)
I believe something has changed in newer versions of Autofac i.e. > 4.9.4. Log4NetModule does not injects and throws no exceptions either. Can you please investigate this? I am using this package for over 6 applications on production and when I update Autofac, logger stops working. Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.