Ejemplo n.º 1
0
 public Service1(ILogFactory _log)
 {
     InitializeComponent();
     this.log            = _log.GetLogger("task1Logger");
     this.logAppointment = _log.GetLogger("task2Logger");
     TestLog();
 }
Ejemplo n.º 2
0
 public static ILogger GetLogger(Type type)
 {
     if (_logFactory == null)
     {
         throw new NullReferenceException(MSG_EX_NO_FACTORY);
     }
     return(_logFactory.GetLogger(type));
 }
Ejemplo n.º 3
0
        public static ILog GetLogger(Type type)
        {
            if (_factory != null)
            {
                return(_factory.GetLogger(type));
            }

            return(Default.GetLogger(type));
        }
Ejemplo n.º 4
0
        public static void Init(ILogFactory logFactory)
        {
            if (logFactory == null)
            {
                throw new ArgumentNullException(nameof(logFactory));
            }

            MainLog    = logFactory.GetLogger("MainLog");
            Http404Log = logFactory.GetLogger("Http404Log");
        }
Ejemplo n.º 5
0
 public ReadingListService(
     ITrelloFactory factory,
     ILogFactory logFactory)
 {
     _board  = factory.Board(TrelloBoardConstants.BoardId);
     _logger = logFactory.GetLogger(this.GetType());
 }
Ejemplo n.º 6
0
 public BaseRedisHelper(IRedisClientManager redisClientManager, ILogFactory logFactory, TimeSpan?ttlTimeSpan)
 {
     _redisClientManager = redisClientManager;
     Logger            = logFactory.GetLogger(GetType());
     _contractResolver = new DefaultContractResolver();
     TtlTimeSpan       = ttlTimeSpan;
 }
Ejemplo n.º 7
0
 public void BuildUp(IBuilderContext context)
 {
     if (context.Existing == null)
     {
         context.Existing = logFactory.GetLogger(this.LogType);
     }
 }
Ejemplo n.º 8
0
 public ExpensesController(
     IExpenseRepository expenseRepository,
     ILogFactory logFactory)
 {
     logger             = logFactory.GetLogger <ExpensesController>();
     _expenseRepository = expenseRepository;
 }
        private async Task <IHtmlDocument> GetHtmlDocumentAsync(string url)
        {
            try {
                _webClient.UserAgent = _boomkatConfiguration.WebClientUserAgent;

                var htmlContent = await _webClient.GetAsync(url);

                var htmlDocument = new HtmlDocumentImpl(new HtmlDocument());
                htmlDocument.LoadHtml(htmlContent);
                return(htmlDocument);
            }
            catch (Exception ex) {
                _logFactory.GetLogger(typeof(BoomkatFeedItemService))
                .ErrorFormat(HtmlWebLoadErrorMessageFormat, url, ex.Message);
                throw new BoomkatServiceException(string.Format(HtmlWebLoadErrorMessageFormat, url, ex.Message));
            }
        }
Ejemplo n.º 10
0
        public static ILogger GetLogger(string loggerName = null, [CallerFilePath] string callerFilePath = null)
        {
            if (loggerName == null)
            {
                loggerName = Path.GetFileNameWithoutExtension(callerFilePath);
            }

            return(_logFactory.GetLogger(loggerName));
        }
Ejemplo n.º 11
0
 public CachedReadingListService(
     IReadingListService readingListService,
     IReadingListCache readingListCache,
     ILogFactory logFactory)
 {
     _readingListService = readingListService;
     _readingListCache   = readingListCache;
     _logger             = logFactory.GetLogger(this.GetType());
 }
Ejemplo n.º 12
0
 public CallbackModule(
     IReadingListCache readingListCache,
     ILogFactory logger,
     ITrelloWebHookSources webHookSource)
 {
     _logger           = logger.GetLogger(GetType());
     _readingListCache = readingListCache;
     _webHookSource    = webHookSource;
 }
Ejemplo n.º 13
0
 public GithubBookRecordService(
     IGitBookRecordCache gitBookRecordCache,
     GithubClient githubFileClient,
     ILogFactory logFactory)
 {
     _gitBookRecordCache = gitBookRecordCache;
     _githubFileClient   = githubFileClient;
     _logger             = logFactory.GetLogger(GetType());
 }
Ejemplo n.º 14
0
        public static ILogger SafeGetCurrentClassLogger(this ILogFactory factory)
        {
            if (factory == null)
            {
                return(NullLogger.Instance);
            }
            string name = GetCurrentClassName(2);

            return(factory.GetLogger(name));
        }
Ejemplo n.º 15
0
 public RecordingService(ILogFactory loggerFactory, IRecordingRepository recordingRepository, ISoundWordsConfiguration soundWordsConfiguration, IDbConnectionFactory dbConnectionFactory, IFileSystem fileSystem, IServerEvents serverEvents, IBackgroundPool backgroundPool)
 {
     _logger = loggerFactory.GetLogger(GetType());
     _recordingRepository     = recordingRepository;
     _soundWordsConfiguration = soundWordsConfiguration;
     _dbConnectionFactory     = dbConnectionFactory;
     _fileSystem     = fileSystem;
     _serverEvents   = serverEvents;
     _backgroundPool = backgroundPool;
 }
Ejemplo n.º 16
0
        static void Test1()
        {
            var logger = logFactory.GetLogger();

            logger.Debug("test1 debug");
            logger.Info("test 1 info");
            logger.Error("test1 error");
            logger.Error("test1 error", new Exception("test exception"));
            logger.ErrorFormat("test1 at {0}", DateTime.Now);
        }
Ejemplo n.º 17
0
 public RebuildJob(ILogFactory logFactory, ISoundWordsConfiguration soundWordsConfiguration, IDbConnectionFactory dbConnectionFactory,
                   IServerEvents serverEvents, IFileSystem fileSystem,
                   Func <string, bool, File.IFileAbstraction> fileAbstractionFactory)
 {
     _logger = logFactory.GetLogger(GetType());
     _soundWordsConfiguration = soundWordsConfiguration;
     _dbConnectionFactory     = dbConnectionFactory;
     _serverEvents            = serverEvents;
     _fileSystem             = fileSystem;
     _fileAbstractionFactory = fileAbstractionFactory;
 }
Ejemplo n.º 18
0
 public async Task <AlbumSearchResult> AlbumSearchAsync(string artist, string album)
 {
     try {
         return(await _serviceClient.GetAsync <AlbumSearchResult>(_urlBuilder.BuildAlbumSearchUrl(artist, album)));
     }
     catch (Exception ex) {
         _logFactory.GetLogger(typeof(SearchService))
         .ErrorFormat(AlbumSearchErrorMessageFormat, artist, album, ex.Message);
         throw new SpotifyServiceException(
                   string.Format(AlbumSearchErrorMessageFormat, artist, album, ex.Message), ex);
     }
 }
Ejemplo n.º 19
0
        public void LogManager_InjectionTest()
        {
            ILogFactory factory = Mocks.CreateMock <ILogFactory>();

            Expect.Call(factory.GetLogger(GetType())).Return(Mocks.DynamicMock <ILog>());
            ReplayAll();

            LogManager.LogFactory = factory;
            ILog log = LogManager.GetLogger(GetType());

            Assert.IsNotNull(log);
            VerifyAll();
        }
Ejemplo n.º 20
0
 public ServiceRunner
 (
     ILogFactory logFactory,
     IPeriodicProcessScheduler periodicProcessScheduler,
     IEventPublisher <IServiceRequest> serviceEventPublisher,
     [ImportMany] IEnumerable <IjTechService> services
 )
 {
     _log = logFactory.GetLogger(this);
     _periodicProcessScheduler = periodicProcessScheduler;
     _serviceEventPublisher    = serviceEventPublisher;
     _services = services.ToList();
 }
Ejemplo n.º 21
0
 public ServiceBoot
 (
     ILogFactory logFactory,
     IServiceInstance serviceInstance,
     IEventPublisher <IServiceRequest> serviceEventPublisher
 )
 {
     _log             = logFactory.GetLogger(this);
     _serviceInstance = serviceInstance;
     serviceEventPublisher.GetEvent <GracefulShutdownRequest>()
     .Take(1)                      // One is enough.
     .Subscribe(OnGracefulShutdownRequest);
 }
Ejemplo n.º 22
0
        public StaticDataProvider(ILogFactory logFactory)
        {
            logger = logFactory.GetLogger <StaticDataProvider>();

            _enumTypes = new Type[]
            {
                typeof(Data.Enums.Currency),
                typeof(Data.Enums.TransactionType)
            };

            string enumsText = string.Join(", ", _enumTypes.Select(e => e.ToString()));

            logger.Info($"Providing StaticData for enums - [ {enumsText} ]");
        }
Ejemplo n.º 23
0
 public TrelloApiKeyAuthenticationHandler(
     IOptionsMonitor <TrelloApiKeyAuthenticationOptions> options,
     ILoggerFactory logger,
     UrlEncoder encoder,
     ISystemClock clock,
     IOptions <TrelloAuthSettings> configuredTrelloAuthSettings,
     ITrelloAuthorizationWrapper trelloAuthWrapper,
     ILogFactory logFactory)
     : base(options, logger, encoder, clock)
 {
     _configuredTrelloAuthSettings = configuredTrelloAuthSettings.Value;
     _trelloAuthWrapper            = trelloAuthWrapper;
     _logger = logFactory.GetLogger(this.GetType());
 }
Ejemplo n.º 24
0
        public BackgroundPool(ILogFactory logFactory, IApplicationLifetime lifetime, IComponentContext componentContext)
        {
            _logger           = logFactory.GetLogger(GetType());
            _lifetime         = lifetime;
            _componentContext = componentContext;

            _lifetime.ApplicationStopped.Register(() =>
            {
                lock (_currentTasksLock)
                {
                    Task.WaitAll(_currentTasks.ToArray());
                }

                _logger.Info("Background pool closed.");
            });
        }
Ejemplo n.º 25
0
        public async Task <string> GetAsync(string url)
        {
            try {
                using (var client = new HttpClient()) {
                    if (!string.IsNullOrWhiteSpace(UserAgent))
                    {
                        client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
                    }

                    var response = await client.GetAsync(url);

                    return(await response.Content.ReadAsStringAsync());
                }
            }
            catch (Exception ex) {
                _logFactory.GetLogger(typeof(WebClient)).ErrorFormat(
                    WebClientErrorMessageFormat, url, ex.Message);
                throw;
            }
        }
        public static void ConfigureExceptionHandler(this IApplicationBuilder app, ILogFactory logFactory)
        {
            var logger = logFactory.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

            app.UseExceptionHandler(appError =>
            {
                appError.Run(async context =>
                {
                    context.Response.ContentType = "application/json";

                    var contextFeature = context.Features.Get <IExceptionHandlerFeature>();
                    if (contextFeature != null)
                    {
                        logger.Error($"Something went wrong: {contextFeature.Error}");
                        var res = new ApiResponseBase();
                        res.SetInternalErrorResponse(context.Response, "Internal Server Error." + contextFeature.Error.Message);
                        await context.Response.WriteAsync(JsonConvert.SerializeObject(res));
                    }
                });
            });
        }
Ejemplo n.º 27
0
        public async Task <T> GetAsync <T>(string url)
        {
            var retries = 0;
            var serviceCallIsSuccessfull = false;

            var responseObject = default(T);

            while (!serviceCallIsSuccessfull &&
                   (retries == 0 || retries < _jsonServiceClientConfiguration.MaxNumberOfRetries))
            {
                try {
                    if (retries > 0)
                    {
                        var milliseconds = _jsonServiceClientConfiguration.SlowDownFactor * (retries * retries);
                        await Task.Delay(milliseconds);
                    }

                    var response = await _webClient.GetAsync(url);

                    serviceCallIsSuccessfull = true;
                    return(JsonConvert.DeserializeObject <T>(response));
                }
                catch (Exception ex) {
                    _logFactory.GetLogger(typeof(WebClient)).ErrorFormat(
                        JsonServiceClientErrorMessageFormat, url, ex.Message);

                    if (retries == _jsonServiceClientConfiguration.MaxNumberOfRetries - 1)
                    {
                        throw;
                    }

                    retries++;
                }
            }

            return(responseObject);
        }
Ejemplo n.º 28
0
        public ServiceInstance
        (
            ILogFactory logFactory,
            IConfiguration configuration,
            IServiceRunner serviceRunner
        )
        {
            try
            {
                _log           = logFactory.GetLogger(this);
                _serviceRunner = serviceRunner;

                //this.ServiceName = configuration[ServiceNameKey];

                InstanceStopped = new ManualResetEvent(false);

                InitializeComponent();
            }
            catch (Exception e)
            {
                _log.Log(LogCatagory.Error, e, "Service Instance caught an unexpected exception on initialise.");
                throw;
            }
        }
Ejemplo n.º 29
0
 public void Intercept(IInvocation invocation)
 {
     _logger = _logFactory.GetLogger(invocation.TargetType);
     if (_logger.IsDebugEnabled)
     {
         _logger.Debug(_invocationLogStringBuilder.BuildLogString(invocation, InvocationPhase.Start));
     }
     try
     {
         invocation.Proceed();
         if (_logger.IsDebugEnabled)
         {
             _logger.Debug(_invocationLogStringBuilder.BuildLogString(invocation, InvocationPhase.End));
         }
     }
     catch (Exception ex)
     {
         if (_logger.IsErrorEnabled)
         {
             _logger.Error(_invocationLogStringBuilder.BuildLogString(invocation, InvocationPhase.Error), ex);
         }
         throw;
     }
 }
Ejemplo n.º 30
0
 public SimilarArtistsResponse GetSimilarArtists(string artist)
 {
     try {
         var similarArtistsResponse =
             _serviceClient.Get <SimilarArtistsResponse>(_urlBuilder.BuildArtistGetSimilatUrl(artist));
         if (similarArtistsResponse.SimilarArtists == null)
         {
             similarArtistsResponse.SimilarArtists = new SimilarArtists {
                 Artists = new Artist[] {}
             };
         }
         if (similarArtistsResponse.SimilarArtists.Artists == null)
         {
             similarArtistsResponse.SimilarArtists.Artists = new Artist[] {};
         }
         return(similarArtistsResponse);
     }
     catch (Exception ex) {
         _logFactory.GetLogger(typeof(ArtistService))
         .ErrorFormat(GetSimilarArtistsErrorMessageFormat, artist, ex.Message);
         throw new LastfmServiceException(
                   string.Format(GetSimilarArtistsErrorMessageFormat, artist, ex.Message), ex);
     }
 }
		public ScoreboardModule(IDataStorage dataStorage, ICryptation cryptation, ILogFactory logger) : base("/api/v1")
		{
			StaticConfiguration.DisableErrorTraces = false;
			m_dataStorage = dataStorage;
			m_cryptation = cryptation;
			m_logger = logger.GetLogger(GetType());

			Get["/ping"] = parameters =>
			{
				var response = (Response)"pong";
				response.StatusCode = HttpStatusCode.OK;

				return response;
			};

			Post["/addScoreBoardData"] = parameters =>
		   {
			   try
			   {
				   var scoreBoardData = this.Bind<ScoreRecord>();
				   int createdId = m_dataStorage.AddScoreRecordToStorage(scoreBoardData);
				   var response = Response.AsJson(createdId);
				   response.StatusCode = HttpStatusCode.Created;
				   return response;
			   }
			   catch (Exception e)
			   {
				   m_logger.Error(e.Message, e);
				   var response = (Response)e.ToString();
				   response.StatusCode = HttpStatusCode.BadRequest;

				   return response;
			   }
		   };

			Get["/gameScoreBoard"] = parameters =>
		   {
			   string gameNameFromQuery = Request.Query["gameName"];
			   string numberOfRecords = Request.Query["count"];
			   int count;
			   if (int.TryParse(numberOfRecords, out count))
			   {
				   try
				   {
					   return Response.AsJson(m_dataStorage.GetScoresForGame(gameNameFromQuery, count));
				   }
				   catch (Exception e)
				   {
					   m_logger.Error(e.Message, e);
					   var response = (Response)e.ToString();
					   response.StatusCode = HttpStatusCode.BadRequest;

					   return response;
				   }
			   }
			   return Response.AsJson(m_dataStorage.GetAllScoresForGame(gameNameFromQuery));
		   };

			Get["/countHigherScores"] = parameters =>
		   {
			   string gameNameFromQuery = Request.Query["gameName"];
			   string scoreFromQuery = Request.Query["score"];
			   int count;
			   if (int.TryParse(scoreFromQuery, out count))
			   {
				   try
				   {
					   return Response.AsJson(m_dataStorage.CountHigherScores(gameNameFromQuery, count));
				   }
				   catch (Exception e)
				   {
					   m_logger.Error(e.Message, e);
					   var response = (Response)e.ToString();
					   response.StatusCode = HttpStatusCode.BadRequest;

					   return response;
				   }
			   }
			   return Response.AsJson(m_dataStorage.GetAllScoresForGame(gameNameFromQuery));

		   };

			Get["/playerScoreBoard"] = parameters =>
		   {
			   try
			   {
				   string playerNameFromQuery = Request.Query["playerName"];
				   return Response.AsJson(m_dataStorage.GetAllScoresForUsername(playerNameFromQuery));
			   }
			   catch (Exception e)
			   {
				   m_logger.Error(e.Message, e);
				   var response = (Response)e.ToString();
				   response.StatusCode = HttpStatusCode.BadRequest;

				   return response;
			   }
		   };

			Get["/gameNames"] = parameters =>
		   {
			   try
			   {
				   return Response.AsJson(m_dataStorage.GetAllGameNames());
			   }
			   catch (Exception e)
			   {
				   m_logger.Error(e.Message, e);
				   var response = (Response)e.ToString();
				   response.StatusCode = HttpStatusCode.BadRequest;

					return response; 
				}
			};
		}