Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OperationContext" /> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="identifier">The identifier used for the operation. If not specified, a random guid will be used.</param>
        /// <param name="description">A description for the operation.</param>
        /// <param name="level">The level used to write the operation details to the logger. By default this is the information level.</param>
        /// <param name="warnIfExceeds">Specifies a limit, if it takes more than this limit, the level will be set to warning. By default this is not used.</param>
        /// <param name="autoSucceedOnExit">Specifies whether or not the operation should be marked with an outcome of <see cref="OperationOutcome.Success"/> if it completes without exception.</param>
        /// <param name="autoFailOnException">Specifies whether or not the operation should be marked with an outcome of <see cref="OperationOutcome.Fail"/> if an exception is detected.</param>
        /// <param name="propertyBag">A colletion of additional properties to associate with the current operation. This is typically an anonymous type.</param>
        internal OperationContext(ILogger logger,
                                  LogEventLevel level,
                                  TimeSpan?warnIfExceeds,
                                  object identifier,
                                  string description,
                                  bool autoSucceedOnExit,
                                  bool autoFailOnException,
                                  object propertyBag)
        {
            _logger              = logger;
            _level               = level;
            _warnIfExceeds       = warnIfExceeds;
            _identifier          = identifier;
            _description         = description;
            _autoSucceedOnExit   = autoSucceedOnExit;
            _autoFailOnException = autoFailOnException;

            _operationContextBookmark = OperationLogContext.PushOperationId(identifier);

            if (propertyBag != null)
            {
                // Save the first contextual property that we set. We then dispose of this bookmark, reverting the stack to what it was previously
                _contextualPropertiesBookmark = PushProperties(propertyBag);
            }

            _logger.Write(_level, BeginOperationMessage, _identifier, _description);

            _sw = Stopwatch.StartNew();
        }
Example #2
0
        public override Symbol VisitOperationLog([NotNull] OperationLogContext context)
        {
            var data = context.parameterList().data(0).Accept(this).AsString;

            seleniumLogger.Log($"Logging to Script log level: {data}", SeleniumScriptLogLevel.InterpreterDetails);
            seleniumLogger.Log(data, SeleniumScriptLogLevel.Script);
            return(null);
        }
Example #3
0
        public override void Publish(string dbconnection, string data, bool sample, bool reduced, string strategy = SqlDbConfiguration.SqlAzureExecutionStrategy)
        {
            base.Publish(dbconnection, data, sample, reduced, strategy);
            string connection = dbconnection;

            SafeWriteDebug("ConnectionString: " + connection);

            using (var db = new OperationLogContext(connection))
            {
                new SetupMigrateDatabaseToLatestVersion <OperationLogContext, Configuration>().InitializeDatabase(db);
            }
        }
Example #4
0
        public bool HasOperationLog(DbContext context)
        {
            bool ret = false;

            using (var ctx = new OperationLogContext(context.Database.Connection.ConnectionString))
            {
                if (Exists(ctx))
                {
                    ret = true;
                }
            }

            return(ret);
        }
Example #5
0
 protected void CreateOperationLogTables(DbContext context)
 {
     using (var ctx = new OperationLogContext(context.Database.Connection.ConnectionString))
     {
         //using (new TransactionScope(TransactionScopeOption.Suppress))
         {
             var objectContext = ((IObjectContextAdapter)ctx).ObjectContext;
             //objectContext.Connection.Open();
             var script = objectContext.CreateDatabaseScript();
             //string script = context.CreateDatabaseScript();
             ctx.Database.ExecuteSqlCommand(script);
             ctx.Database.CreateIndex <OperationLog>(x => x.ObjectType);
             ctx.Database.CreateIndex <OperationLog>(x => x.OperationType);
             ctx.Database.CreateIndex <OperationLog>(x => x.LastModified);
             //objectContext.Connection.Close();
         }
     }
 }
Example #6
0
        private static bool Exists(OperationLogContext context)
        {
            bool flag;

            using (SqlDbConfiguration.ExecutionStrategySuspension)
                using (new TransactionScope(TransactionScopeOption.Suppress))
                {
                    flag = context.Database.Exists();
                }

            if (flag)
            {
                try
                {
                    context.OperationLogs.Count();
                    return(true);
                }
                catch (EntityException)
                {
                }
            }
            return(false);
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OperationContext" /> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="identifier">The identifier used for the operation. If not specified, a random guid will be used.</param>
        /// <param name="description">A description for the operation.</param>
        /// <param name="propertyBag">A colletion of additional properties to associate with the current operation. This is typically an anonymous type.</param>
        /// <param name="options">Configuration options for the operation context.</param>
        internal BaseOperationContext(ILogger logger,
                                      string identifier,
                                      string description,
                                      object propertyBag,
                                      TOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            _logger      = logger;
            _identifier  = identifier;
            _description = description;
            _options     = options;

            _operationContextBookmark = OperationLogContext.PushOperationId(identifier);

            if (propertyBag != null)
            {
                // Save the first contextual property that we set. We then dispose of this bookmark, reverting the stack to what it was previously
                _contextualPropertiesBookmark = PushProperties(propertyBag);
            }
        }
Example #8
0
 /// <summary>
 /// Enriches a given log event with data from the current <see cref="OperationContext"/>.
 /// </summary>
 /// <param name="logEvent">The log event to enrich.</param>
 /// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
 internal static void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     OperationLogContext.EnrichLogEvent(logEvent, propertyFactory);
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LogInterceptor"/> class.
 /// </summary>
 /// <param name="logContext">The log context.</param>
 public LogInterceptor(OperationLogContext logContext)
 {
     _logContext = logContext;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LogInterceptor"/> class.
 /// </summary>
 /// <param name="logContext">The log context.</param>
 public LogInterceptor(OperationLogContext logContext)
 {
     _logContext = logContext;
 }