예제 #1
0
        public void AddLogItem(ILogItem log)
        {
            var logItem = LogItem.FromILogItem(log);

            var pathToFile = ResolvePath(
                logItem.Id.ToString(),
                logItem,
                ".json",
                true
                );

            if (File.Exists(pathToFile))
            {
                return;
            }

            var serialized = JsonConvert.SerializeObject(
                logItem,
                Formatting.None,
                new JsonSerializerSettings {
                DefaultValueHandling = DefaultValueHandling.Include
            });

            using (StreamWriter s = File.CreateText(pathToFile))
            {
                s.Write(serialized);
            }
        }
예제 #2
0
        //private IServiceProvider serviceProvider;

        public void AddLogItem(ILogItem log)
        {
            // since we are using EF to add to the log we need ot avoid
            // logging EF related things, otherwise every time we log we generate more log events
            // continuously
            // might be better to use the normal mssql ado log repository instead
            // need to decouple logging repos from core repos

            if (log.Logger.Contains("EntityFrameworkCore"))
            {
                return;
            }

            var logItem = LogItem.FromILogItem(log);

            using (var context = new LoggingDbContext(dbContextOptions))
            {
                context.Add(logItem);
                context.SaveChanges();
            }

            // learned by experience for this situation we need to create transient instance of the dbcontext
            // for logging because the dbContext we have passed in is scoped to the request
            // and it causes problems to save changes on the context multiple times during a request
            // since we may log mutliple log items in a given request we need to create the dbcontext as needed
            // we can still use the normal dbContext for querying
            //dbContext.Add(logItem);
            //dbContext.SaveChanges();

            //return logItem.Id;
        }
        public void AddLogItem(ILogItem log)
        {
            // since we are using EF to add to the log we need to avoid
            // logging EF related things, otherwise every time we log we generate more log events
            // continuously
            // might be better to use the normal mssql ado log repository instead
            // need to decouple logging repos from core repos

            if (log.Logger.Contains("EntityFrameworkCore"))
            {
                return;
            }

            var logItem = LogItem.FromILogItem(log);

            using (var context = _contextFactory.CreateContext())
            {
                context.LogItems.Add(logItem);
                context.SaveChanges();
            }
        }
        public void AddLogItem(ILogItem log)
        {
            var logItem = LogItem.FromILogItem(log);

            Task t = commands.CreateAsync(options.ProjectId, logItem.Id.ToString(), logItem);
        }