private void LogDbTraceWithProperties(
            string database
            , string procedureOrTypeOfExecuted
            , TimeSpan stopwatchElapsed
            , string commandText
            , string command
            , bool logViaWcf
            )
        {
            var logger = LogManager.GetLogger(database);

            var loggingEvent = new LoggingEvent(GetType(), logger.Logger.Repository, logger.Logger.Name, Level.Trace,
                                                string.Format(commandText, command),
                                                null);

            AddPropertiesDbTrace(database, procedureOrTypeOfExecuted, stopwatchElapsed, commandText, command,
                                 loggingEvent);

            try
            {
                // We want all exception/trace/audit/debug messages to be logged to file if the calling method was not explicitly called with "logViaWcf" parameter set to true
                // we also want all exception/trace/audit/debug messages to be logged to file if the "_logEverythingToFile" overrride was set to true (in application config)
                if (Convert.ToBoolean(_logEverythingToFile) || !logViaWcf)
                {
                    logger.Logger.Log(loggingEvent);
                }
            }
            catch (AggregateException ae)
            {
                ae.Handle(x => true);
            }
            catch (Exception)
            {
                // ignored
            }

            try
            {
                // We want all exception/trace/audit/debug messages to be logged to database via WCF if the calling method was explicitly called with "logViaWcf" parameter set to true
                // We also log to database via WCF if we have override property "_logEverythingViaWcf" set to true (in application config)
                // We also have one additional override property "_dontLogAnythingViaWcf", if this is set to true (in application config) we dont log anything to database (via WCF)
                if (logViaWcf || Convert.ToBoolean(_logEverythingViaWcf) && !Convert.ToBoolean(_dontLogAnythingViaWcf))
                {
                    if (_wcfAppenderService == null)
                    {
                        _wcfAppenderService = WcfLogFactory.GetWcfLogger();
                    }

                    _wcfAppenderService.AppendToLog(loggingEvent);
                }
            }
            catch (AggregateException ae)
            {
                ae.Handle(x => true);
            }
            catch (Exception)
            {
                // ignored
            }
        }
        private void LogMessageWithProperties(
            object logSource
            , string message
            , Level level
            , Exception exception
            , bool logViaWcf = false
            )
        {
            _logManager = GetMyLogger(logSource, level, _isMock);

            LogEvent = new LoggingEvent(logSource.GetType(), _logManager.Logger.Repository, _logManager.Logger.Name,
                                        level,
                                        message,
                                        null);

            AddProperties(logSource, exception, LogEvent);

            try
            {
                // We want all exception/trace/audit/debug messages to be logged to file if the calling method was not explicitly called with "logViaWcf" parameter set to true
                // we also want all exception/trace/audit/debug messages to be logged to file if the "_logEverythingToFile" overrride was set to true (in application config)
                if (Convert.ToBoolean(_logEverythingToFile) || !logViaWcf)
                {
                    _logManager.Logger.Log(LogEvent);
                }
            }
            catch (AggregateException ae)
            {
                ae.Handle(x => true);
            }
            catch (Exception)
            {
                // ignored
            }

            try
            {
                // We want all exception/trace/audit/debug messages to be logged to database via WCF if the calling method was explicitly called with "logViaWcf" parameter set to true
                // We also log to database via WCF if we have override property "_logEverythingViaWcf" set to true (in application config)
                // We also have one additional override property "_dontLogAnythingViaWcf", if this is set to true (in application config) we dont log anything to database (via WCF)
                if (logViaWcf || Convert.ToBoolean(_logEverythingViaWcf) && !Convert.ToBoolean(_dontLogAnythingViaWcf))
                {
                    if (_wcfAppenderService == null)
                    {
                        _wcfAppenderService = WcfLogFactory.GetWcfLogger();
                    }

                    _wcfAppenderService.AppendToLog(LogEvent);
                }
            }
            catch (AggregateException ae)
            {
                ae.Handle(x => true);
            }
            catch (Exception)
            {
                // ignored
            }
        }
        public void TestInitialize()
        {
            // Not fake...
            _dataContextAsync = new SimpleMembershipDataContextAsync();

            // Is fake...
            _fakeConfigurationRepository = new FakeConfigFileConfigurationRepository();
            _fakeConfigurationRepository.FakeSettingsDictionary.Clear();
            _fakeConfigurationRepository.FakeSettingsDictionary.Add("Log4NetSettingsFile", "Log4Net.config.xml");
            _fakeConfigurationRepository.FakeSettingsDictionary.Add("LogEverythingViaWCF", "false");
            _fakeConfigurationRepository.FakeSettingsDictionary.Add("DontLogAnythingViaWCF", "false");
            _fakeConfigurationRepository.FakeSettingsDictionary.Add("LogEverythingToFile", "true");
            _fakeConfigurationRepository.FakeSettingsDictionary.Add("LoggingServiceURL",
                                                                    "http://localhost:63247/LogWCF.svc");

            var dir = Directory.GetCurrentDirectory();
            var resourceFileInfo = new FileInfo(Path.Combine(dir, "Log4Net.config.xml"));

            // Is fake...
            _fakeContextService = new FakeThreadContextService
            {
                FakeGetContextualFullFilePath  = resourceFileInfo.FullName,
                FakeUserNameForTestingPurposes = "SimpleMembershipServiceUnitTest"
            };

            // Is fake...
            _fakewcfAppenderService = new FakeWcfAppenderService(_fakeConfigurationRepository);


            // Is fake...
            _loggingService = new Log4NetLoggingService(_fakeConfigurationRepository, _fakeContextService,
                                                        _fakewcfAppenderService, true);

            // Not fake...
            _uow = new SimpleMembershipUnitOfWorkAsync(_dataContextAsync, _loggingService);

            // Not fake...
            _simpleMembershipService = new WebSecurity(_uow, _loggingService);


            InitDb();
        }
        public Log4NetLoggingService(
            IApplicationConfiguration configurationRepository
            , IAddLoggingContextProvider contextService
            , IWcfAppenderService wcfAppenderService
            , bool isMock = false
            )
        {
            _isMock = isMock;
            _configurationRepository = configurationRepository ??
                                       throw new ArgumentNullException(nameof(configurationRepository));
            _contextService     = contextService ?? throw new ArgumentNullException(nameof(contextService));
            _wcfAppenderService = wcfAppenderService;

            try
            {
                _log4NetConfigFileName = _configurationRepository.GetLocationOfLog4NetConfigFile();
            }
            catch (Exception)
            {
                throw new ApplicationException("Log4NetSettingsFile key missing from web/app configuration.");
            }

            if (string.IsNullOrEmpty(_log4NetConfigFileName))
            {
                throw new ApplicationException("Log4NetSettingsFile key missing from web/app configuration.");
            }

            try
            {
                // Override setting, logs everything to database (via windows communication foundation)
                _logEverythingViaWcf = _configurationRepository.GetLogEverythingViaWCF();
            }
            catch (Exception)
            {
                // fallback, default is false
                _logEverythingViaWcf = "false";
            }

            try
            {
                // Override setting, disables all logging to database (via windows communication foundation)
                _dontLogAnythingViaWcf = _configurationRepository.GetDontLogAnythingViaWCF();
            }
            catch (Exception)
            {
                // fallback, default is false
                _dontLogAnythingViaWcf = "false";
            }


            try
            {
                // Override setting, disables all logging to database (via windows communication foundation)
                _logEverythingToFile = _configurationRepository.GetLogEverythingToFile();
            }
            catch (Exception)
            {
                // fallback, default is true
                _logEverythingToFile = "true";
            }

            SetupLogger();
        }