AuditScopeOptions

Namespace: Audit.NET
We found 10 examples in language CSharp for this search. You will see 36 fragments of code.

Other methods


        public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
        {
            await using var _ = await _auditScopeFactory.CreateAsync(new AuditScopeOptions(typeof(TRequest).Name, null, new
            {
                Request = request
            }));

            return await next();
        }

        /// <summary>
        /// Shortcut to create an audit scope
        /// </summary>
        public static AuditScope Create(AuditScopeOptions options)
        {
            return new AuditScope(options).Start();
        }
        /// <summary>
        /// Shortcut to create an audit scope
        /// </summary>
        public static async Task<AuditScope> CreateAsync(AuditScopeOptions options)
        {
            return await new AuditScope(options).StartAsync();
        }
        /// <summary>
        /// Creates an audit scope with the given creation options as a Fluent API.
        /// </summary>
        public static IAuditScope Create(Action<IAuditScopeOptionsConfigurator> config)
        {
            var options = new AuditScopeOptions(config);
            return new AuditScope(options).Start();
        }
        /// <summary>
        /// Creates an audit scope with the given creation options as a Fluent API.
        /// </summary>
        public static async Task<IAuditScope> CreateAsync(Action<IAuditScopeOptionsConfigurator> config)
        {
            var options = new AuditScopeOptions(config);
            return await new AuditScope(options).StartAsync();
        }
        /// <summary>
        /// Shortcut to create an audit scope with the given Event type and Target.
        /// </summary>
        /// <param name="eventType">A string representing the type of the event.</param>
        /// <param name="target">The target object getter.</param>
        /// <param name="extraFields">An anonymous object that contains additional fields to be merged into the audit event.</param>
        public static AuditScope Create(string eventType, Func<object> target, object extraFields = null)
        {
            var options = new AuditScopeOptions(eventType: eventType, targetGetter: target, extraFields: extraFields);
            return new AuditScope(options).Start();
        }
        /// <summary>
        /// Shortcut to create an audit scope with the given Event type and Target.
        /// </summary>
        /// <param name="eventType">A string representing the type of the event.</param>
        /// <param name="target">The target object getter.</param>
        /// <param name="extraFields">An anonymous object that contains additional fields to be merged into the audit event.</param>
        public static async Task<AuditScope> CreateAsync(string eventType, Func<object> target, object extraFields = null)
        {
            var options = new AuditScopeOptions(eventType: eventType, targetGetter: target, extraFields: extraFields);
            return await new AuditScope(options).StartAsync();
        }

        #region IAuditScopeFactory implementation
        /// <summary>
        /// Creates an audit scope with the given creation options.
        /// </summary>
        [MethodImpl(MethodImplOptions.NoInlining)]
        public IAuditScope Create(AuditScopeOptions options)
        {
            return new AuditScope(options).Start();
        }

        /// <summary>
        /// Creates an audit scope with the given creation options.
        /// </summary>
        [MethodImpl(MethodImplOptions.NoInlining)]
        public async Task<IAuditScope> CreateAsync(AuditScopeOptions options)
        {
            return await new AuditScope(options).StartAsync();
        }
        #endregion

        /// <summary>
        /// Creates an audit scope with the given creation options as a Fluent API.
        /// </summary>
        [MethodImpl(MethodImplOptions.NoInlining)]
        public IAuditScope Create(Action<IAuditScopeOptionsConfigurator> config)
        {
            var options = new AuditScopeOptions(config);
            return new AuditScope(options).Start();
        }

        /// <summary>
        /// Creates an audit scope with the given creation options as a Fluent API.
        /// </summary>
        [MethodImpl(MethodImplOptions.NoInlining)]
        public async Task<IAuditScope> CreateAsync(Action<IAuditScopeOptionsConfigurator> config)
        {
            var options = new AuditScopeOptions(config);
            return await new AuditScope(options).StartAsync();
        }

        /// <summary>
        /// Creates an audit scope with the given extra fields, and saves it right away using the globally configured data provider. Shortcut for CreateAndSave().
        /// </summary>
        /// <param name="eventType">Type of the event.</param>
        /// <param name="extraFields">An anonymous object that can contain additional fields to be merged into the audit event.</param>
        [MethodImpl(MethodImplOptions.NoInlining)]
        public void Log(string eventType, object extraFields)
        {
            using (var scope = new AuditScope(new AuditScopeOptions(eventType, null, extraFields, null, null, true)))
            {
                scope.Start();
            }
        }
        /// <summary>
        /// Creates an audit scope with the given extra fields, and saves it right away using the globally configured data provider. Shortcut for CreateAndSaveAsync().
        /// </summary>
        /// <param name="eventType">Type of the event.</param>
        /// <param name="extraFields">An anonymous object that can contain additional fields to be merged into the audit event.</param>
        [MethodImpl(MethodImplOptions.NoInlining)]
        public async Task LogAsync(string eventType, object extraFields)
        {
            using (var scope = new AuditScope(new AuditScopeOptions(eventType, null, extraFields, null, null, true)))
            {
                await scope.StartAsync();
            }
        }

        [Test]
        [Category("AzureDocDb")]
        public void TestAzureCosmos_CustomId()
        {
            var id = Guid.NewGuid().ToString().Replace("-", "").ToUpper();
            var dp = new AzureCosmos.Providers.AzureCosmosDataProvider()
            {
                Endpoint = AzureSettings.AzureDocDbUrl,
                Database = "Audit",
                Container = "AuditTest",
                AuthKey = AzureSettings.AzureDocDbAuthKey,
                IdBuilder = _ => id
            };
            var eventType = TestContext.CurrentContext.Test.Name + new Random().Next(1000, 9999);
            var auditEvent = new AuditEvent();
            using (var scope = AuditScope.Create(new AuditScopeOptions()
            {
                DataProvider = dp,
                EventType = eventType,
                CreationPolicy = EventCreationPolicy.InsertOnStartReplaceOnEnd,
                AuditEvent = auditEvent
            }))
            {
                scope.SetCustomField("value", "added");
            };

            var ev = dp.GetEvent(id, eventType);
            
            Assert.AreEqual(id, auditEvent.CustomFields["id"].ToString());
            Assert.AreEqual(auditEvent.CustomFields["value"].ToString(), ev.CustomFields["value"].ToString());
            Assert.AreEqual(eventType, auditEvent.EventType);
        }
        
        [Test]
        [Category("AzureDocDb")]
        public async Task TestAzureCosmos_CustomIdAsync()
        {
            var id = Guid.NewGuid().ToString().Replace("-", "").ToUpper();

            var dp = new AzureCosmos.Providers.AzureCosmosDataProvider()
            {
                Endpoint = AzureSettings.AzureDocDbUrl,
                Database = "Audit",
                Container = "AuditTest",
                AuthKey = AzureSettings.AzureDocDbAuthKey,
                IdBuilder = _ => id
            };
            var eventType = TestContext.CurrentContext.Test.Name + new Random().Next(1000, 9999);
            var auditEvent = new AuditEvent();

            using (var scope = await AuditScope.CreateAsync(new AuditScopeOptions()
            {
                DataProvider = dp,
                EventType = eventType,
                CreationPolicy = EventCreationPolicy.InsertOnStartReplaceOnEnd,
                AuditEvent = auditEvent
            }))
            {
                scope.SetCustomField("value", "added");
            };

            var ev = await dp.GetEventAsync(id, eventType);

            Assert.AreEqual(id, auditEvent.CustomFields["id"].ToString());
            Assert.AreEqual(auditEvent.CustomFields["value"].ToString(), ev.CustomFields["value"].ToString());
            Assert.AreEqual(eventType, auditEvent.EventType);
        }

using System;
using System.Reflection;

namespace Audit.Core
{
    /// <summary>
    /// Options for AuditScope creation
    /// </summary>
    public class AuditScopeOptions
    {
        /// <summary>
        /// Gets or sets the string representing the type of the event.
        /// </summary>
        public string EventType { get; set; }
        /// <summary>
        /// Gets or sets the target object getter (a getter to the object to track)
        /// </summary>
        public Func<object> TargetGetter { get; set; }
        /// <summary>
        /// Gets or sets the anonymous object that contains additional fields to be merged into the audit event.
        /// </summary>
        public object ExtraFields { get; set; }
        /// <summary>
        /// Gets or Sets the data provider builder.
        /// </summary>
        public Func<AuditDataProvider> DataProviderFactory { get; set; }
        /// <summary>
        /// Gets or sets the data provider to use.
        /// </summary>
        public AuditDataProvider DataProvider { get { return DataProviderFactory?.Invoke(); } set { DataProviderFactory = () => value; } }
        /// <summary>
        /// Gets or sets the event creation policy to use.
        /// </summary>
        public EventCreationPolicy? CreationPolicy { get; set; }
        /// <summary>
        /// Gets or sets a value indicating whether this scope should be immediately saved after creation
        /// </summary>
        public bool IsCreateAndSave { get; set; }
        /// <summary>
        /// Gets or sets the initial audit event to use, or NULL to create a new instance of AuditEvent
        /// </summary>
        public AuditEvent AuditEvent { get; set; }
        /// <summary>
        /// Gets or sets the value used to indicate how many frames in the stack should be skipped to determine the calling method
        /// </summary>
        public int SkipExtraFrames { get; set; }
        /// <summary>
        /// Gets or sets a specific calling method to store on the event. NULL to use the calling stack to determine the calling method.
        /// </summary>
        public MethodBase CallingMethod { get; set; }

        /// <summary>
        /// Creates an instance of options for an audit scope creation.
        /// </summary>
        /// <param name="eventType">A string representing the type of the event.</param>
        /// <param name="targetGetter">The target object getter.</param>
        /// <param name="extraFields">An anonymous object that contains additional fields to be merged into the audit event.</param>
        /// <param name="creationPolicy">The event creation policy to use. NULL to use the configured default creation policy.</param>
        /// <param name="dataProvider">The data provider to use. NULL to use the configured default data provider.</param>
        /// <param name="isCreateAndSave">To indicate if the scope should be immediately saved after creation.</param>
        /// <param name="auditEvent">The initialized audit event to use, or NULL to create a new instance of AuditEvent.</param>
        /// <param name="skipExtraFrames">Used to indicate how many frames in the stack should be skipped to determine the calling method.</param>
        public AuditScopeOptions(
            string eventType = null,
            Func<object> targetGetter = null,
            object extraFields = null,
            AuditDataProvider dataProvider = null,
            EventCreationPolicy? creationPolicy = null,
            bool isCreateAndSave = false,
            AuditEvent auditEvent = null,
            int skipExtraFrames = 0)
        {
            EventType = eventType;
            TargetGetter = targetGetter;
            ExtraFields = extraFields;
            CreationPolicy = creationPolicy ?? Configuration.CreationPolicy;
            DataProviderFactory = dataProvider != null ? () => dataProvider : Configuration.DataProviderFactory;
            IsCreateAndSave = isCreateAndSave;
            AuditEvent = auditEvent;
            SkipExtraFrames = skipExtraFrames;
            CallingMethod = null;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="AuditScopeOptions"/> class.
        /// </summary>
        public AuditScopeOptions()
            : this(null, null, null, null, null)
        {
        }

        public AuditScopeOptions(Action<IAuditScopeOptionsConfigurator> config)
            : this(null, null, null, null, null)
        {
            if (config != null)
            {
                var scopeConfig = new AuditScopeOptionsConfigurator();
                config.Invoke(scopeConfig);

                EventType = scopeConfig._options.EventType;
                TargetGetter = scopeConfig._options.TargetGetter;
                ExtraFields = scopeConfig._options.ExtraFields;
                CreationPolicy = scopeConfig._options.CreationPolicy;
                DataProviderFactory = scopeConfig._options.DataProviderFactory;
                IsCreateAndSave = scopeConfig._options.IsCreateAndSave;
                AuditEvent = scopeConfig._options.AuditEvent;
                SkipExtraFrames = scopeConfig._options.SkipExtraFrames;
                CallingMethod = scopeConfig._options.CallingMethod;
            }

        }
    }
}


        public object[] AllocateInputs()
        {
            return _baseInvoker.AllocateInputs();
        }

        /// <summary>
        /// Returns an object and a set of output objects from an instance and set of input objects.
        /// </summary>
        /// <param name="instance">The object to be invoked.</param>
        /// <param name="inputs">The inputs to the method.</param>
        /// <param name="outputs">The outputs from the method.</param>
        public object Invoke(object instance, object[] inputs, out object[] outputs)
        {
            object result = null;
            // Create the Wcf audit event
            var auditWcfEvent = CreateWcfAuditEvent(instance, inputs);
            // Create the audit scope
            var eventType = _eventType.Replace("{contract}", auditWcfEvent.ContractName)
                .Replace("{operation}", auditWcfEvent.OperationName);
            var auditEventWcf = new AuditEventWcfAction()
            {
                WcfEvent = auditWcfEvent
            };
            // Create the audit scope
            using (var auditScope = AuditScope.Create(new AuditScopeOptions()
            {
                EventType = eventType,
                CreationPolicy = _creationPolicy,
                AuditEvent = auditEventWcf,
                DataProvider = GetAuditDataProvider(instance),
                CallingMethod = _operationDescription.SyncMethod ?? _operationDescription.TaskMethod
            }))
            {
                // Store a reference to this audit scope on a thread static field
                AuditBehavior.CurrentAuditScope = auditScope;
                try
                {
                    result = _baseInvoker.Invoke(instance, inputs, out outputs);
                }
                catch (Exception ex)
                {
                    AuditBehavior.CurrentAuditScope = null;
                    auditWcfEvent.Fault = GetWcfFaultData(ex);
                    auditWcfEvent.Success = false;
                    (auditScope.Event as AuditEventWcfAction).WcfEvent = auditWcfEvent;
                    throw;
                }
                AuditBehavior.CurrentAuditScope = null;
                auditWcfEvent.OutputParameters = GetEventElements(outputs);
                auditWcfEvent.Result = new AuditWcfEventElement(result);
                (auditScope.Event as AuditEventWcfAction).WcfEvent = auditWcfEvent;
            }
            return result;
        }

        /// <summary>
        /// Asynchronous implementation of the Invoke (Begin)
        /// </summary>
        public IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state)
        {
            IAsyncResult result = null;
            // Create the Wcf audit event
            var auditWcfEvent = CreateWcfAuditEvent(instance, inputs);
            // Create the audit scope
            var eventType = _eventType.Replace("{contract}", auditWcfEvent.ContractName)
                .Replace("{operation}", auditWcfEvent.OperationName);
            var auditEventWcf = new AuditEventWcfAction()
            {
                WcfEvent = auditWcfEvent
            };
            // Create the audit scope
            var auditScope = AuditScope.Create(new AuditScopeOptions()
            {
                EventType = eventType,
                CreationPolicy = _creationPolicy,
                AuditEvent = auditEventWcf,
                DataProvider = GetAuditDataProvider(instance),
                CallingMethod = _operationDescription.SyncMethod ?? _operationDescription.TaskMethod
            });
            // Store a reference to this audit scope
            var callbackState = new AuditScopeState()
            {
                AuditScope = auditScope,
                OriginalUserCallback = callback,
                OriginalUserState = state
            };
            AuditBehavior.CurrentAuditScope = auditScope;
            try
            {
                result = _baseInvoker.InvokeBegin(instance, inputs, this.InvokerCallback, callbackState);
            }
            catch (Exception ex)
            {
                AuditBehavior.CurrentAuditScope = null;
                auditWcfEvent.Fault = GetWcfFaultData(ex);
                auditWcfEvent.Success = false;
                (auditScope.Event as AuditEventWcfAction).WcfEvent = auditWcfEvent;
                auditScope.Dispose();
                throw;
            }
            AuditBehavior.CurrentAuditScope = null;
            return new AuditScopeAsyncResult(result, callbackState);
        }

        /// <summary>
        /// Asynchronous implementation of the Invoke (End)
        /// </summary>
        public object InvokeEnd(object instance, out object[] outputs, IAsyncResult result)
        {
            var auditAsyncResult = result as AuditScopeAsyncResult;
            var auditScopeState = auditAsyncResult.AuditScopeState;
            object callResult;
            var auditScope = auditScopeState.AuditScope;
            var auditWcfEvent = (auditScope.Event as AuditEventWcfAction).WcfEvent;
            try
            {
                callResult = _baseInvoker.InvokeEnd(instance, out outputs, auditAsyncResult.OriginalAsyncResult);
            }
            catch (Exception ex)
            {
                AuditBehavior.CurrentAuditScope = null;
                auditWcfEvent.Fault = GetWcfFaultData(ex);
                auditWcfEvent.Success = false;
                (auditScope.Event as AuditEventWcfAction).WcfEvent = auditWcfEvent;
                auditScope.Dispose();
                throw;
            }
            AuditBehavior.CurrentAuditScope = null;
            auditWcfEvent.OutputParameters = GetEventElements(outputs);
            auditWcfEvent.Result = new AuditWcfEventElement(callResult);
            (auditScope.Event as AuditEventWcfAction).WcfEvent = auditWcfEvent;
            auditScope.Dispose();
            return callResult;
        }
        #endregion

        #region Private Methods
        private WcfEvent CreateWcfAuditEvent(object instance, object[] inputs)
        {
            var securityContext = ServiceSecurityContext.Current;
            var operationContext = OperationContext.Current;
            var imProps = OperationContext.Current.IncomingMessageProperties;
            var endpoint = imProps.ContainsKey(RemoteEndpointMessageProperty.Name) ? imProps[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty : null;
            return new WcfEvent()
            {
                Action = _operation.Action,
                ReplyAction = _operation.ReplyAction,
                ContractName = _operationDescription.DeclaringContract.Name,
                IsAsync = _operationDescription.SyncMethod == null,
                MethodSignature = (_operationDescription.SyncMethod ?? _operationDescription.TaskMethod).ToString(),
                OperationName = _operation.Name,
                ClientAddress = endpoint?.Address,
                HostAddress = string.Join(", ", operationContext.InstanceContext.Host?.BaseAddresses?.Select(a => a.AbsoluteUri)),
                InstanceQualifiedName = instance.GetType().AssemblyQualifiedName,
                InputParameters = GetEventElements(inputs),
                IdentityName = securityContext?.WindowsIdentity?.Name ?? securityContext?.PrimaryIdentity?.Name,
                Success = true
            };
        }

        /// <summary>
        /// Get the dataprovider from property AuditDataProvider
        /// </summary>
        private AuditDataProvider GetAuditDataProvider(object instance)
        {
            var prop = instance.GetType().GetProperty("AuditDataProvider", typeof(AuditDataProvider));
            if (prop != null)
            {
                return prop.GetGetMethod().Invoke(instance, null) as AuditDataProvider;
            }
            return null;
        }

        /// <summary>
        /// Creates an audit scope with the given creation options.
        /// </summary>
        IAuditScope Create(AuditScopeOptions options);
        /// <summary>
        /// Creates an audit scope with the given creation options.
        /// </summary>
        Task<IAuditScope> CreateAsync(AuditScopeOptions options);


        public IAuditScopeOptionsConfigurator AuditEvent(AuditEvent auditEvent)
        {
            _options.AuditEvent = auditEvent;
            return this;
        }

        public IAuditScopeOptionsConfigurator CallingMethod(MethodBase method)
        {
            _options.CallingMethod = method;
            return this;
        }

        public IAuditScopeOptionsConfigurator CreationPolicy(EventCreationPolicy creationPolicy)
        {
            _options.CreationPolicy = creationPolicy;
            return this;
        }

        public IAuditScopeOptionsConfigurator DataProvider(AuditDataProvider dataProvider)
        {
            _options.DataProvider = dataProvider;
            return this;
        }

        public IAuditScopeOptionsConfigurator DataProvider(Func<AuditDataProvider> dataProviderFactory)
        {
            _options.DataProviderFactory = dataProviderFactory;
            return this;
        }

        public IAuditScopeOptionsConfigurator EventType(string eventType)
        {
            _options.EventType = eventType;
            return this;
        }

        [Test]
        public void Test_DataProviderFactory()
        {
            GetProviderCount = 0;
            var options = new AuditScopeOptions(_ => _.DataProvider(GetProvider).CreationPolicy(EventCreationPolicy.InsertOnStartReplaceOnEnd));
            Assert.AreEqual(0, GetProviderCount);
            using (var scope = AuditScope.Create(options))
            {
                Assert.AreEqual(1, GetProviderCount);
                scope.SetCustomField("custom", "value");
                scope.Save();
            }
            Assert.AreEqual(1, GetProviderCount);
            options = new AuditScopeOptions(_ => _.DataProvider(GetProvider).CreationPolicy(EventCreationPolicy.Manual));
            using (var scope = new AuditScope(options))
            {
                Assert.AreEqual(2, GetProviderCount);
                scope.Save();
                scope.Save();
            }
            Assert.AreEqual(2, GetProviderCount);
            Audit.Core.Configuration.DataProviderFactory = GetProvider;
            using (var scope = AuditScope.Create("Test", null, new { custom = "value" }))
            { 
                Assert.AreEqual(3, GetProviderCount);
                scope.Discard();
            }
            Assert.AreEqual(3, GetProviderCount);

            Audit.Core.Configuration.Setup().UseFactory(GetProvider);
            using (var scope = AuditScope.Create("Test", null, new { custom = "value" }))
            {
                Assert.AreEqual(4, GetProviderCount);
                scope.Save();
            }
            Assert.AreEqual(4, GetProviderCount);
        }
        private AuditDataProvider GetProvider()
        {
            GetProviderCount++;
            return new NullDataProvider();
        }


        [OneTimeSetUp]
        public void Setup()
        {
            _adapter = new MemoryTarget();
            global::NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(_adapter, global::NLog.LogLevel.Debug);
        }

        [Test]
        public void Test_NLog_InsertOnEnd()
        {
            Audit.Core.Configuration.Setup()
                .UseNLog(_ => _
                    .LogLevel(ev => (LogLevel)ev.CustomFields["LogLevel"])
                    .Logger(ev => LogManager.GetLogger(typeof(NLogTests).ToString())));

            _adapter.Logs.Clear();

            using (var s = new AuditScopeFactory().Create(new AuditScopeOptions()
            {
                CreationPolicy = EventCreationPolicy.InsertOnEnd,
                EventType = nameof(Test_NLog_InsertOnEnd),
                ExtraFields = new
                {
                    LogLevel = LogLevel.Debug
                }
            }))
            {
                s.Event.CustomFields["LogLevel"] = LogLevel.Error;
            }

            var events = _adapter.Logs.Select(l => new NLogObject(l)).ToArray();
            Assert.AreEqual(1, events.Length);
            Assert.AreEqual(LogLevel.Error, events[0].Level);
            Assert.AreEqual(nameof(Test_NLog_InsertOnEnd), JsonAdapter.Deserialize<AuditEvent>(events[0].MessageObject).EventType);
        }
        [Test]
        public void Test_NLog_InsertOnStartReplaceOnEnd()
        {
            Audit.Core.Configuration.Setup()
                .UseNLog(_ => _
                    .LogLevel(NLog.LogLevel.Info));

            _adapter.Logs.Clear();

            using (var s = new AuditScopeFactory().Create(new AuditScopeOptions()
            {
                CreationPolicy = EventCreationPolicy.InsertOnStartReplaceOnEnd,
                EventType = nameof(Test_NLog_InsertOnStartReplaceOnEnd)
            }))
            {

            }

            var events = _adapter.Logs.Select(l => new NLogObject(l)).ToArray();
            Assert.AreEqual(2, events.Length);
            Assert.AreEqual(nameof(Test_NLog_InsertOnStartReplaceOnEnd), JsonAdapter.Deserialize<AuditEvent>(events[0].MessageObject).EventType);
            Assert.AreEqual(nameof(Test_NLog_InsertOnStartReplaceOnEnd), JsonAdapter.Deserialize<AuditEvent>(events[1].MessageObject).EventType);
            Assert.AreEqual(JsonAdapter.Deserialize<AuditEvent>(events[0].MessageObject).CustomFields["EventId"].ToString(), JsonAdapter.Deserialize<AuditEvent>(events[1].MessageObject).CustomFields["EventId"].ToString());
        }

        [Test]
        public void Test_NLog_InsertOnStartInsertOnEnd()
        {
            Audit.Core.Configuration.Setup()
                .UseNLog(_ => _
                    .LogLevel(ev => (LogLevel)ev.CustomFields["LogLevel"])
                    .Logger(ev => LogManager.GetLogger(typeof(NLogTests).ToString())));

            _adapter.Logs.Clear();

            using (var s = new AuditScopeFactory().Create(new AuditScopeOptions()
            {
                CreationPolicy = EventCreationPolicy.InsertOnStartInsertOnEnd,
                EventType = nameof(Test_NLog_InsertOnStartInsertOnEnd),
                ExtraFields = new
                {
                    LogLevel = LogLevel.Debug
                }
            }))
            {
                s.Event.CustomFields["LogLevel"] = LogLevel.Error;
            }

            var events = _adapter.Logs.Select(l => new NLogObject(l)).ToArray();
            Assert.AreEqual(2, events.Length);
            Assert.AreEqual(LogLevel.Debug, events[0].Level);
            Assert.AreEqual(LogLevel.Error, events[1].Level);
            Assert.AreEqual(nameof(Test_NLog_InsertOnStartInsertOnEnd), JsonAdapter.Deserialize<AuditEvent>(events[0].MessageObject).EventType);
            Assert.AreEqual(nameof(Test_NLog_InsertOnStartInsertOnEnd), JsonAdapter.Deserialize<AuditEvent>(events[1].MessageObject).EventType);
            Assert.AreNotEqual(JsonAdapter.Deserialize<AuditEvent>(events[0].MessageObject).CustomFields["EventId"], JsonAdapter.Deserialize<AuditEvent>(events[1].MessageObject).CustomFields["EventId"]);
        }

Audit.Core.AuditScopeOptions : Object

Constructors :

public AuditScopeOptions(String eventType = null, Func<Object> targetGetter = null, Object extraFields = null, AuditDataProvider dataProvider = null, Nullable<EventCreationPolicy> creationPolicy = null, Boolean isCreateAndSave = False, AuditEvent auditEvent = null, Int32 skipExtraFrames = 0)
public AuditScopeOptions()
public AuditScopeOptions(Action<IAuditScopeOptionsConfigurator> config = )

Methods :

public String get_EventType()
public Void set_EventType(String value = )
public Func<Object> get_TargetGetter()
public Void set_TargetGetter(Func<Object> value = )
public Object get_ExtraFields()
public Void set_ExtraFields(Object value = )
public Func<AuditDataProvider> get_DataProviderFactory()
public Void set_DataProviderFactory(Func<AuditDataProvider> value = )
public AuditDataProvider get_DataProvider()
public Void set_DataProvider(AuditDataProvider value = )
public Nullable<EventCreationPolicy> get_CreationPolicy()
public Void set_CreationPolicy(Nullable<EventCreationPolicy> value = )
public Boolean get_IsCreateAndSave()
public Void set_IsCreateAndSave(Boolean value = )
public AuditEvent get_AuditEvent()
public Void set_AuditEvent(AuditEvent value = )
public Int32 get_SkipExtraFrames()
public Void set_SkipExtraFrames(Int32 value = )
public MethodBase get_CallingMethod()
public Void set_CallingMethod(MethodBase value = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()