Lazy Logger

Scenario:

Logger with Lazy loading

Solution:

  • Loading Logger when needed
    using System.Collections;
    namespace Web.Models
    {
        public static class Class
        {
            private static readonly Lazy<Logger> Logger;
    
            public static Class()
            {
                Logger = new Lazy<Logger>(() =>
                   Get<ILoggerFactory>().GetLogger()));
            }
            public bool Validate()
            {
                Logger.Value.Error(e, $"Error")
            }
        }
    }

No comments:

Post a Comment

Move Github Sub Repository back to main repo

 -- delete .gitmodules git rm --cached MyProject/Core git commit -m 'Remove myproject_core submodule' rm -rf MyProject/Core git remo...