public ReifiedProjection(IProjection <TEvent, TState> projection, IProjectionCacheProvider cacheProvider = null, ILogAdapter log = null) { if (projection == null) { throw new ArgumentNullException(nameof(projection)); } // Cache the projection's full name. This shields us against projection authors // writing changing names. Name = projection.FullName; if (Name == null) { throw new ArgumentException("Projection must have a name", nameof(projection)); } var nameRegexp = new Regex("^[-a-zA-Z0-9_]{1,16}$"); if (!nameRegexp.IsMatch(Name)) { throw new ArgumentException("Projection name must match [-a-zA-Z0-9_]{1,16}", nameof(projection)); } _projection = projection; _cacheProvider = cacheProvider; _log = log; _log?.Debug("Using projection: " + Name); Reset(); }
/// <summary> /// Updates the Adapter, adds if not already added, Updates IgnoreList for the given Adapter /// </summary> /// <param name="logAdapter"></param> /// <param name="ignoreList"></param> /// <exception cref="LoggerAdapterIsNullException"></exception> /// <exception cref="IgnoreListIsNullException"></exception> public static void UpdateAdapter(ILogAdapter logAdapter, List <LogLevel> ignoreList) { if (logAdapter == null) { throw new ArgumentNullException("logAdapter is null"); } if (ignoreList == null) { throw new ArgumentNullException("ignoreList is null"); } if (logAdapter == null) { throw new LoggerAdapterIsNullException(); } if (ignoreList == null) { throw new IgnoreListIsNullException(); } if (_adapters.ContainsKey(logAdapter)) { _adapters[logAdapter] = ignoreList; } else { _adapters.Add(logAdapter, ignoreList); } }
protected BaseTest(ILogAdapter extraLogging) { LogCapture = Logs.Capture(); TestLogging = Logs.ToMultiple(extraLogging, LogCapture); TestLogger = TestLogging.Logger(""); BasicContext = new LdClientContext(new BasicConfiguration(Configuration.Default(BasicSdkKey), TestLogger), Configuration.Default("")); BasicTaskExecutor = new TaskExecutor("test-sender", TestLogger); // The following line prevents intermittent test failures that happen only in .NET // Framework, where background tasks (including calls to Task.Delay) are very excessively // slow to start-- on the order of many seconds. The issue appears to be a long-standing // one that is described here, where the very low default setting of ThreadPool.SetMinThreads // causes new worker tasks to be severely throttled: // http://joeduffyblog.com/2006/07/08/clr-thread-pool-injection-stuttering-problems/ // // We've seen experimentally that this setting defaults to 2 when running the tests in .NET // Framework, versus at least 12 when running them in .NET Core. // // It is theoretically possible for something similar to happen in a real application, but // since that would affect all tasks in the application, we assume that developers would // need to tune this parameter in any case, not only because of our SDK. ThreadPool.SetMinThreads(100, 100); }
protected BaseExceptionHandler(ILogAdapter <T> logger, string errorShortCode, int statusCode, string detail = null) { _logger = logger; _errorShortCode = errorShortCode; _statusCode = statusCode; _detail = detail; }
// Token: 0x06000F9F RID: 3999 RVA: 0x0003F6CB File Offset: 0x0003D8CB public GlobalConnectionSettingsProvider(ILogAdapter logAdapter) { if (logAdapter == null) { throw new ArgumentNullException("logAdapter", "The logAdapter argument cannot be null."); } this.log = logAdapter; }
/// <summary> /// Use this constructor if you want to be able to send logs to the Xunit test output buffer. /// Xunit will pass the <see cref="ITestOutputHelper"/> to the test subclass's constructor /// if you declare a parameter of that type. /// </summary> /// <param name="testOutput"></param> public BaseTest(ITestOutputHelper testOutput) : this() { _testLogging = Logs.ToMultiple( Logs.ToMethod(testOutput.WriteLine), _logCapture ); _testLogger = _testLogging.Logger(""); }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="baseLoggerName">value for <see cref="BaseLoggerName"/></param> /// <param name="logAdapter">value for <see cref="LogAdapter"/></param> public LoggingConfiguration( string baseLoggerName, ILogAdapter logAdapter ) { BaseLoggerName = baseLoggerName; LogAdapter = logAdapter ?? Logs.None; }
/// <summary> Initialize and start the service. </summary> /// <remarks> /// This will start a background task that performs all processing /// and regularly updates the contents. /// </remarks> /// <param name="storage"> Identifies where the event stream data is stored. </param> /// <param name="projections"> All available <see cref="IProjection{T}"/> instances. </param> /// <param name="projectionCache"> Used to save projected state. </param> /// <param name="log"> Used for logging. </param> /// <param name="cancel"> Stops the background tasks when called. </param> public static EventStreamService <TEvent, TState> StartNew( StorageConfiguration storage, IEnumerable <IProjection <TEvent> > projections, IProjectionCacheProvider projectionCache, ILogAdapter log, CancellationToken cancel) => new EventStreamService <TEvent, TState>( storage, projections, projectionCache, log, cancel);
public static ILogAdapter Timestamped(this ILogAdapter log) { if (log == null) { return(null); } return(new TimestampLogAdapter(log)); }
/// <summary> /// Updates the logging adapter. /// </summary> public static void SetAdapter(ILogAdapter adapter) { if (null == adapter) { adapter = new NoOpLogAdapter(); } _log = adapter; }
public SqlDumper(ILogAdapter logAdapter, IProvider provider, IDbCommand insertCommand, IDbCommand selectCommand, IDbCommand updateCommand, IDbCommand deleteCommand) { this.logAdapter = logAdapter; this.provider = provider; this.updateCommand = updateCommand; this.insertCommand = insertCommand; this.selectCommand = selectCommand; this.deleteCommand = deleteCommand; }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="baseLoggerName">value for <see cref="BaseLoggerName"/></param> /// <param name="logAdapter">value for <see cref="LogAdapter"/></param> /// <param name="logDataSourceOutageAsErrorAfter">value for <see cref="LogDataSourceOutageAsErrorAfter"/></param> public LoggingConfiguration( string baseLoggerName, ILogAdapter logAdapter, TimeSpan?logDataSourceOutageAsErrorAfter ) { BaseLoggerName = baseLoggerName; LogAdapter = logAdapter ?? Logs.None; LogDataSourceOutageAsErrorAfter = logDataSourceOutageAsErrorAfter; }
public Log(ILogAdapter[] logAdapters) { if (logAdapters == null) throw new ArgumentNullException("logAdapters"); if (logAdapters.Length == 0) throw new ArgumentException("At least one (1) log adapter must be provided.", "logAdapters"); this.logAdapters = logAdapters; }
public BinaryBookStorage(ILogAdapter logger, string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new AggregateException(); } this.logger = logger; FilePath = filePath; }
/// <summary> Initialize and start the service. </summary> /// <remarks> /// This will start a background task that performs all processing /// and regularly updates the contents. /// </remarks> /// <param name="storage"> Identifies where the event stream data is stored. </param> /// <param name="projections"> All available <see cref="IProjection{T}"/> instances. </param> /// <param name="projectionCache"> Used to save projected state. </param> /// <param name="events"> /// Called on each event committed to the stream (including intial catch-up of /// already commited events). /// <see cref="EventStreamWrapper{TEvent,TState}.OnEachCommitted"/> /// </param> /// <param name="log"> Used for logging. </param> /// <param name="cancel"> Stops the background tasks when called. </param> public static EventStreamService <TEvent, TState> StartNew( StorageConfiguration storage, IEnumerable <IProjection <TEvent> > projections, IProjectionCacheProvider projectionCache, IEnumerable <Tuple <EventStream <TEvent> .Listener, uint> > events, ILogAdapter log, CancellationToken cancel) { return(new EventStreamService <TEvent, TState>( storage, projections, projectionCache, events, log, cancel)); }
/// <summary> /// Remove the Adapter from the subscription List /// </summary> /// <param name="logAdapter"></param> public static void RemoveAdapter(ILogAdapter logAdapter) { if (logAdapter == null) { throw new ArgumentNullException("logAdapter is null"); } if (_adapters.ContainsKey(logAdapter)) { _adapters.Remove(logAdapter); } }
/// <summary> /// Creates an instance of a log Manager and attaches it /// to the static Current property that is reusable throughout /// the application. /// /// This method should be called once when the application starts /// </summary> /// <param name="adapter"></param> /// <returns></returns> public static LogManager Create(ILogAdapter adapter) { lock (SyncRoot) { if (_Current == null) { LogManager manager = new LogManager(adapter); _Current = manager; } return(_Current); } }
/// <summary> /// Creates an instance of a log Manager and attaches it /// to the static Current property that is reusable throughout /// the application. /// /// This method should be called once when the application starts /// </summary> /// <param name="adapter"></param> /// <returns></returns> public static LogManager Create(ILogAdapter adapter) { lock (SyncRoot) { if (_Current == null) { LogManager manager = new LogManager(adapter); _Current = manager; } return _Current; } }
public BookService(IComparer <Book> comparer, ILogAdapter logger) { if (ReferenceEquals(comparer, null)) { comparer = Comparer <Book> .Default; } if (ReferenceEquals(logger, null)) { throw new ArgumentNullException(); } this.logger = logger; booksStorage = new SortedSet <Book>(comparer); }
/// <remarks> /// This constructor is private so that it is obvious (via <c>StartNew</c>) /// that background tasks are being creatd. /// </remarks> private EventStreamService( StorageConfiguration storage, IEnumerable <IProjection <TEvent> > projections, IProjectionCacheProvider projectionCache, ILogAdapter log, CancellationToken cancel) : base(TimeSpan.FromSeconds(30), cancel) { _log = log; _cancel = cancel; Wrapper = new EventStreamWrapper <TEvent, TState>(storage, projections, projectionCache, log); Quarantine = Wrapper.Quarantine; Ready = Task.Run(Initialize, cancel); }
/// <summary> /// Default constructor - does not use the Xunit test output buffer. /// </summary> public BaseTest() { _logCapture = Logs.Capture(); _testLogging = _logCapture; _testLogger = _testLogging.Logger(""); // The following line prevents intermittent test failures that can happen due to the low // default setting of ThreadPool.SetMinThreads causing new worker tasks to be severely // throttled: http://joeduffyblog.com/2006/07/08/clr-thread-pool-injection-stuttering-problems/ // This makes it difficult to test things such as timeouts. We believe it not to be a real // issue in non-test scenarios, since the tests are starting and stopping an unusually large // number of async tasks in a way that regular use of EventSource would not do. ThreadPool.SetMinThreads(100, 100); }
/// <summary> /// Adds a Writer to Logger, ignores Nothing /// </summary> /// <param name="logAdapter"></param> /// <exception cref="LoggerAdapterIsNullException"></exception> public static void UpdateAdapter(ILogAdapter logAdapter) { if (logAdapter == null) { throw new LoggerAdapterIsNullException(); } if (_adapters.ContainsKey(logAdapter)) { _adapters[logAdapter] = new List <LogLevel>(); } else { _adapters.Add(logAdapter, new List <LogLevel>()); } }
/// <summary> /// Creates an instance of the LogManager based on the /// settings configured in the web.config file /// </summary> /// <returns></returns> public static LogManager Create(LogAdapterTypes logType) { ILogAdapter adapter = null; if (logType == LogAdapterTypes.Sql) { adapter = new SqlLogAdapter(); } else if (logType == LogAdapterTypes.Xml) { adapter = new XmlLogAdapter(); } return(Create(adapter)); }
public BookService(IEnumerable <Book> collection, IComparer <Book> comparer, ILogAdapter logger) { if (ReferenceEquals(collection, null)) { logger.Error($"Faild to create new books storage -> collection is null\n {new StackTrace()}"); throw new ArgumentNullException(); } if (ReferenceEquals(comparer, null)) { comparer = Comparer <Book> .Default; } this.logger = logger; booksStorage = new SortedSet <Book>(collection, comparer); }
public void Setup() { _profileRepo = Substitute.For <IProfileRepo>(); _hashedAdapter = Substitute.For <IHashedAdapter>(); _otpService = Substitute.For <IOtpService>(); _logAdapter = Substitute.For <ILogAdapter>(); _notifyAdapter = Substitute.For <INotifyAdapter>(); _failedCounter = Substitute.For <IFailedCounter>(); _authenticationService = new AuthenticationService(_profileRepo, _hashedAdapter, _otpService, _notifyAdapter); var failedCounterDecorator = new FailedCounterDecorator(_authenticationService, _failedCounter); var logDecorator = new LogDecorator(failedCounterDecorator, _logAdapter, _failedCounter); _authenticationService = logDecorator; }
public static ConnectionSettingsManager GetInstanceForModernOutlook(ILogAdapter logAdapter) { if (logAdapter == null) { throw new ArgumentNullException("logAdapter", "The logAdapter parameter cannot be null."); } logAdapter.RegisterLogMetaData("ConnectionSettingsDiscovery", typeof(ConnectionSettingsDiscoveryMetadata)); GlobalConnectionSettingsProvider globalConnectionSettingsProvider = new GlobalConnectionSettingsProvider(logAdapter); return(new ConnectionSettingsManager(new IConnectionSettingsWriteProvider[] { globalConnectionSettingsProvider }, new IConnectionSettingsReadProvider[] { new O365ConnectionSettingsProvider(logAdapter), globalConnectionSettingsProvider })); }
internal static async Task Catchup( IReifiedProjection projection, IEventStream stream, CancellationToken cancel = default, ILogAdapter log = null) { try { // Load project and discard events before that. log?.Info("[ES init] loading projections."); await projection.TryLoadAsync(cancel).ConfigureAwait(false); var catchUp = projection.Sequence + 1; log?.Info($"[ES init] advancing stream to seq {catchUp}."); var streamSequence = await stream.DiscardUpTo(catchUp, cancel).ConfigureAwait(false); if (cancel.IsCancellationRequested) { return; } if (streamSequence != projection.Sequence) { log?.Warning( $"[ES init] projection seq {projection.Sequence} not found in stream (max seq is {streamSequence}: resetting everything."); // Cache is apparently beyond the available sequence. Could happen in // development environments with non-persistent events but persistent // caches. Treat cache as invalid and start from the beginning. stream.Reset(); projection.Reset(); } } catch (Exception e) { log?.Warning("[ES init] error while reading cache.", e); // Something went wrong when reading the cache. Stop. stream.Reset(); projection.Reset(); } }
/// <remarks> /// This constructor is private so that it is obvious (via <c>StartNew</c>) /// that background tasks are being creatd. /// </remarks> private EventStreamService( StorageConfiguration storage, IEnumerable <IProjection <TEvent> > projections, IProjectionCacheProvider projectionCache, IEnumerable <Tuple <EventStream <TEvent> .Listener, uint> > events, ILogAdapter log, CancellationToken cancel) { _log = log; _cancel = cancel; Wrapper = new EventStreamWrapper <TEvent, TState>(storage, projections, projectionCache, log); Quarantine = Wrapper.Quarantine; if (events != null) { foreach (var pair in events) { Wrapper.OnEachCommitted(pair.Item1, pair.Item2); } } Ready = Task.Run(Initialize, cancel); Task.Run(Loop, cancel); }
public InvalidTargetPatternExceptionHandler(ILogAdapter <InvalidTargetPatternException> logger) : base(logger, "invalid-target-pattern-specified", StatusCodes.Status400BadRequest) { }
/// <summary> /// Specifies the implementation of logging to use. /// </summary> /// <remarks> /// <para> /// The <a href="https://github.com/launchdarkly/dotnet-logging"><c>LaunchDarkly.Logging</c></a> API defines the /// <c>ILogAdapter</c> interface to specify where log output should be sent. By default, it is set to /// <c>Logs.ToConsole</c>, meaning that output will be sent to <c>Console.Error</c>. You may use other /// <c>LaunchDarkly.Logging.Logs</c> methods, or a custom implementation, to handle log output differently. /// <c>Logs.None</c> disables logging (equivalent to <see cref="Components.NoLogging"/>). /// </para> /// <para> /// For more about logging adapters, see the <a href="https://launchdarkly.github.io/dotnet-logging">API /// documentation</a> for <c>LaunchDarkly.Logging</c>. /// </para> /// <para> /// If you don't need to customize any options other than the adapter, you can call /// <see cref="Components.Logging(ILogAdapter)"/> as a shortcut rather than using /// <see cref="LoggingConfigurationBuilder"/>. /// </para> /// </remarks> /// <example> /// <code> /// // This example configures the SDK to send log output to a file writer. /// var writer = File.CreateText("sdk.log"); /// var config = Configuration.Builder("my-sdk-key") /// .Logging(Components.Logging().Adapter(Logs.ToWriter(writer))) /// .Build(); /// </code> /// </example> /// <param name="adapter">an <c>ILogAdapter</c> for the desired logging implementation; /// <see langword="null"/> to use the default implementation</param> /// <returns>the same builder</returns> public LoggingConfigurationBuilder Adapter(ILogAdapter adapter) { _logAdapter = adapter; return(this); }
protected BigSegmentStoreBaseTests(ITestOutputHelper testOutput) { _testLogging = TestLogging.TestOutputAdapter(testOutput); }
protected BigSegmentStoreBaseTests() { _testLogging = Logs.None; }
/// <summary> /// Constructor /// </summary> /// <param name="adapter">Instance of ILogAdapter</param> public Log(ILogAdapter adapter) { _adapter = adapter; }
public static void SetAdapter(ILogAdapter adapter) { Assert.NotNull(adapter, "adapter"); Log.adapter = adapter; }
public IZendeskClient Create(Uri baseUri, ZendeskDefaultConfiguration configuration, ISerializer serializer = null, IHttpChannel httpChannel = null, ILogAdapter logger = null) { return new ZendeskClient(baseUri, configuration, serializer, httpChannel, logger); }
/// <summary> /// Main signature allows creating of manager with an adapter /// to specify logging target /// /// Available Adapters are: /// SqlLogAdapter /// XmlLogAdapter (n/a) /// TextLogAdapter (n/a) /// EventLogAdapter (n/a) /// </summary> /// <param name="logAdapter"></param> public LogManager(ILogAdapter logAdapter) { LogAdapter = logAdapter; }