/// <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(); }
/// <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); } }