コード例 #1
0
ファイル: LoggingContext.cs プロジェクト: Takas0522/LearnNlog
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
                optionsBuilder.UseSqlServer("Data Source=localhost;Initial Catalog=Logging;Integrated Security=True;");
            }
            var fact = new EntityFrameworkLogger();
            optionsBuilder.UseLoggerFactory(fact.GetLoggerFactory());
        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
                optionsBuilder.UseSqlServer("Server=(localdb)\\ProjectsV13;Database=LearnWebApiUsingOData.DB;Trusted_Connection=True;");
            }
            var fact = new EntityFrameworkLogger();
            optionsBuilder.UseLoggerFactory(fact.GetLoggerFactory());
        }
コード例 #3
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Data Source=(localdb)\\ProjectsV13;Initial Catalog=DotNetLab2021Feb.Database");
            }
            var fact = new EntityFrameworkLogger();
            optionsBuilder.UseLoggerFactory(fact.GetLoggerFactory());
        }
コード例 #4
0
ファイル: SeatService.cs プロジェクト: Noorivandi/SeatShare
        private void doJob()
        {
            short wait_bar_index = 0;

            char[] wait_bar = new char[] { '|', '/', '-', '\\' };
            bool   debug    = JobServiceConfig.Instance.Debug;

            if (debug)
            {
                if (_ef_logger == null)
                {
                    _ef_logger = new EntityFrameworkLogger(_logger);
                }
                DbInterception.Add(new EntityFrameworkLogger(_logger));
            }

            int delay_time = JobServiceConfig.Instance.DelayTime;
            var jobSrv     = StaticServiceFactory.Create <IBackstageJobService>();

            _logger.Info("start get all base info data from database");
            var baseInfoServices = ServiceFactory.CreateAll <IMemoryCachedService>();

            baseInfoServices.ForEachAction(x =>
            {
                x.IgnoreSecurity();
                try
                {
                    x.GetAll();
                }
                catch (Exception ex)
                {
                    var serviceType = AopUtils.GetAllInterfaces(x).First(y => y.Name.StartsWith("IService") && y.IsGenericType);
                    var messg       = String.Format("Invoking GetAll method on service {0} cause throw exception", serviceType.GetGenericArguments()[0].Name);
                    _logger.Error(messg);
                }
            });
            bool job_fetched = false;

            _queue = new ConcurrentDictionary <string, int>();
            string   server      = String.IsNullOrEmpty(JobServiceConfig.Instance.Server) ? Environment.MachineName : JobServiceConfig.Instance.Server;
            DateTime lastFixTime = DateTime.MinValue;

            do
            {
                if (Environment.UserInteractive)
                {
                    if (Console.CursorLeft > 0)
                    {
                        Console.WriteLine();
                    }

                    Console.Write(wait_bar[wait_bar_index++]);

                    if (wait_bar_index > wait_bar.Length - 1)
                    {
                        wait_bar_index = 0;
                    }

                    Console.CursorLeft = 0;
                }

                job_fetched = false;
                try
                {
                    BackstageJob job = null;
                    try
                    {
                        string[] ignore_queue_names = _queue.Where(x => x.Value >= JobServiceConfig.Instance.GetQueueCapacity(x.Key))
                                                      .Select(x => x.Key)
                                                      .Distinct()
                                                      .ToArray();

                        job = jobSrv.Pop(server, ignore_queue_names);
                    }
                    catch (Exception ex)
                    {
                        _logger.ErrorFormat("cannot pop backstage job because {0}", ex, ex.Message);
                        Thread.Sleep(delay_time);
                        continue;
                    }

                    if (job != null)
                    {
                        if (Environment.UserInteractive)
                        {
                            Console.WriteLine();
                        }

                        _queue.AddOrUpdate(job.Queue ?? Constants.BackstageJobs.Queue.Default, 1, (key, value) => value + 1);

                        job_fetched = true;
                        _logger.InfoFormat("a job {0} in service {1} candidated to run as {2} in queue {3}", job.Action, job.Service, job.RunAs, job.Queue);

                        ThreadPool.QueueUserWorkItem(new WaitCallback(run), job);
                    }

                    if ((DateTime.Now - lastFixTime).TotalMinutes > 10)
                    {
                        lastFixTime = DateTime.Now;
                        jobSrv.FixFetchedButNotRunJobs();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine();
                    _logger.ErrorFormat("an exception occurred on executing job", ex);
                }

                TransactionContext.Current.Clear();

                if (!job_fetched)
                {
                    Thread.Sleep(delay_time);
                }
            } while (!_stop);
            canStop();
        }