public void Scopes() { StringSerializer writer; ILogFactory logFactory = CreateLogFactory(out writer); ILog applicationLog = logFactory.Scope("Application"); applicationLog.Debug("Hello, World"); Assert.AreEqual(1, writer.Messages.Count); Assert.AreEqual("Root.Application", writer.Messages[0].ScopeName); ILog app2Log = logFactory.Scope("App2"); app2Log.Debug("App2"); Assert.AreEqual(2, writer.Messages.Count); Assert.AreEqual("Root.App2", writer.Messages[1].ScopeName); ILog bootLog = applicationLog.Factory.Scope("Bootstrap"); bootLog.Debug("Boot1"); Assert.AreEqual(3, writer.Messages.Count); Assert.AreEqual("Root.Application.Bootstrap", writer.Messages[2].ScopeName); }
public ApiClient(IOptions <ApiClientConfiguration> configuration, TokenContainer token, HttpClient http, CommandMapper commandMapper, QueryMapper queryMapper, IExceptionHandler exceptionHandler, IEventDispatcher eventDispatcher, Interop interop, ILogFactory logFactory, Json json) { Ensure.NotNull(configuration, "configuration"); Ensure.NotNull(token, "token"); Ensure.NotNull(http, "http"); Ensure.NotNull(commandMapper, "commandMapper"); Ensure.NotNull(queryMapper, "queryMapper"); Ensure.NotNull(exceptionHandler, "exceptionHandler"); Ensure.NotNull(eventDispatcher, "eventDispatcher"); Ensure.NotNull(interop, "interop"); Ensure.NotNull(logFactory, "logFactory"); Ensure.NotNull(json, "json"); this.configuration = configuration.Value; this.token = token; this.http = http; this.commandMapper = commandMapper; this.queryMapper = queryMapper; this.exceptionHandler = exceptionHandler; this.eventDispatcher = eventDispatcher; this.interop = interop; this.log = logFactory.Scope("ApiClient"); this.json = json; http.BaseAddress = this.configuration.ApiUrl; EnsureAuthorization(); }
/// <summary> /// Creates new instance with <paramref name="delegateFactory"/> for property and constructor delegates. /// </summary> /// <param name="delegateFactory">The factory for delegates for fast access.</param> /// <param name="logFactory">The factory for the log to write debug information.</param> public ReflectionCompositeTypeProvider(ICompositeDelegateFactory delegateFactory, ILogFactory logFactory) { Ensure.NotNull(delegateFactory, "delegateFactory"); Ensure.NotNull(logFactory, "logFactory"); this.delegateFactory = delegateFactory; this.logFactory = logFactory.Scope("ReflectionCompositeTypeProvider").Factory; }
public ApiTokenValidator(IQueryDispatcher queries, ILogFactory logFactory) { Ensure.NotNull(queries, "queries"); Ensure.NotNull(logFactory, "logFactory"); this.queries = queries; this.log = logFactory.Scope("TokenValidator"); }
public HandlerCollection(ILogFactory logFactory, HandlerDescriptorProvider descriptorProvider) { Ensure.NotNull(logFactory, "logFactory"); Ensure.NotNull(descriptorProvider, "descriptorProvider"); this.log = logFactory.Scope("Handlers"); this.descriptorProvider = descriptorProvider; }
public SignalRListener(ApiHubService apiHub, ILogFactory logFactory) { Ensure.NotNull(apiHub, "apiHub"); Ensure.NotNull(logFactory, "logFactory"); this.apiHub = apiHub; this.log = logFactory.Scope("SignalRListener"); }
public BrowserEventDispatcher(FormatterContainer formatters, ILogFactory logFactory) { Ensure.NotNull(formatters, "formatters"); Ensure.NotNull(logFactory, "logFactory"); this.formatters = formatters; this.log = logFactory.Scope("BrowserEventDispatcher"); }
private void InitializeErrorHandler() { executorFactory = new FileLogBatchFactory(TimeSpan.FromSeconds(30)); logService = new IsolatedLogService(); logFactory = new DefaultLogFactory() .AddSerializer(AddDisposable(new FileLogSerializer(new DefaultLogFormatter(), () => settings.LogLevel, executorFactory))) .AddSerializer(AddDisposable(new ErrorLogSerializer(new DefaultLogFormatter(), executorFactory))) #if DEBUG .AddConsole() #endif ; ILog rootLog = logFactory.Scope("Root"); ExceptionHandlerBuilder builder = new ExceptionHandlerBuilder(); builder .Filter <UnauthorizedAccessException>() .Handler(new UnauthorizedAccessExceptionHandler(settings, this, () => { mainWindow?.Close(); mainFactory.ClearService(); })); builder .Filter(e => !(e is UnauthorizedAccessException)) .Handler(new LogExceptionHandler(rootLog)) .Handler(new MessageBoxExceptionHandler(this)); exceptionHandler = builder; }
public UserMiddleware(ServerConnectionState serverConnection, ProfileStorage localStorage, ILogFactory logFactory) { Ensure.NotNull(serverConnection, "serverConnection"); Ensure.NotNull(localStorage, "localStorage"); Ensure.NotNull(logFactory, "logFactory"); this.serverConnection = serverConnection; this.localStorage = localStorage; this.log = logFactory.Scope("UserMiddleware"); }
/// <summary> /// Creates new instance that uses <paramref name="longRunnerThreshold"/> to threshold 'long runnner' contexts. /// </summary> /// <param name="dateTimeProvider">The provider of execution delay.</param> /// <param name="longRunnerThreshold">The timespan to be used as threshold when deciding whether the context is 'long runner'.</param> /// <param name="logFactory">A log factory.</param> public TimerSchedulingProvider(IDateTimeProvider dateTimeProvider, TimeSpan longRunnerThreshold, ILogFactory logFactory) { Ensure.NotNull(dateTimeProvider, "dateTimeProvider"); EnsureThreshold(longRunnerThreshold, "longRunnerThreshold"); Ensure.NotNull(logFactory, "logFactory"); this.dateTimeProvider = dateTimeProvider; this.longRunnerThreshold = longRunnerThreshold; this.log = logFactory.Scope("TimerSchedulingProvider"); }
public HandlerCollection(ILogFactory logFactory, Dictionary <Type, HashSet <HandlerDescriptor> > storage, HandlerDescriptorProvider descriptorProvider) { Ensure.NotNull(logFactory, "logFactory"); Ensure.NotNull(storage, "storage"); Ensure.NotNull(descriptorProvider, "descriptorProvider"); this.log = logFactory.Scope("Handlers"); this.storage = storage; this.descriptorProvider = descriptorProvider; }
public PullToRefreshInterop(IJSRuntime jsRuntime, IEventDispatcher events, Navigator navigator, ILogFactory logFactory) { Ensure.NotNull(jsRuntime, "jsRuntime"); Ensure.NotNull(events, "events"); Ensure.NotNull(navigator, "navigator"); this.jsRuntime = jsRuntime; this.events = events; this.navigator = navigator; this.log = logFactory.Scope("PullToRefresh"); }
public void LoggingExtensionMethods() { StringSerializer writer; ILogFactory logFactory = CreateLogFactory(out writer); ILog log = logFactory.Scope("Application"); log.Debug("M1"); EnsureMessage(writer, 0, "Root.Application", LogLevel.Debug, "M1"); log.Debug("M{0}", 2); EnsureMessage(writer, 1, "Root.Application", LogLevel.Debug, "M2"); log.Info("M3"); EnsureMessage(writer, 2, "Root.Application", LogLevel.Info, "M3"); log.Info("M{0}", 4); EnsureMessage(writer, 3, "Root.Application", LogLevel.Info, "M4"); log.Warning("M5"); EnsureMessage(writer, 4, "Root.Application", LogLevel.Warning, "M5"); log.Warning("M{0}", 6); EnsureMessage(writer, 5, "Root.Application", LogLevel.Warning, "M6"); log.Error("M7"); EnsureMessage(writer, 6, "Root.Application", LogLevel.Error, "M7"); log.Error("M{0}", 8); EnsureMessage(writer, 7, "Root.Application", LogLevel.Error, "M8"); NotImplementedException e1 = Ensure.Exception.NotImplemented(); log.Error(e1); EnsureMessage(writer, 8, "Root.Application", LogLevel.Error, e1); NotImplementedException e2 = Ensure.Exception.NotImplemented(); log.Error(e2, "M9"); EnsureMessage(writer, 9, "Root.Application", LogLevel.Error, new ExceptionModel("M9", e2)); NotImplementedException e3 = Ensure.Exception.NotImplemented(); log.Error(e3, "M{0}", 10); EnsureMessage(writer, 10, "Root.Application", LogLevel.Error, new ExceptionModel("M10", e3)); log.Fatal("M11"); EnsureMessage(writer, 11, "Root.Application", LogLevel.Fatal, "M11"); log.Fatal("M{0}", 12); EnsureMessage(writer, 12, "Root.Application", LogLevel.Fatal, "M12"); NotImplementedException e4 = Ensure.Exception.NotImplemented(); log.Fatal(e4); EnsureMessage(writer, 13, "Root.Application", LogLevel.Fatal, e4); NotImplementedException e5 = Ensure.Exception.NotImplemented(); log.Fatal(e5, "M13"); EnsureMessage(writer, 14, "Root.Application", LogLevel.Fatal, new ExceptionModel("M13", e5)); NotImplementedException e6 = Ensure.Exception.NotImplemented(); log.Fatal(e6, "M{0}", 14); EnsureMessage(writer, 15, "Root.Application", LogLevel.Fatal, new ExceptionModel("M14", e6)); }
public JsonLocalStorage(IFormatter formatter, ILocalStorageService localStorage, ILogFactory logFactory, string key) { Ensure.NotNull(formatter, "formatter"); Ensure.NotNull(localStorage, "localStorage"); Ensure.NotNull(logFactory, "logFactory"); Ensure.NotNullOrEmpty(key, "key"); this.formatter = formatter; this.localStorage = localStorage; this.log = logFactory.Scope(GetType().Name); this.key = key; }
internal PersistentCommandDispatcher(TreeQueue queue, TreeQueueThreadPool threadPool, ICommandDistributor distributor, ICommandPublishingStore store, ISerializer formatter, ISchedulingProvider schedulingProvider, ILogFactory logFactory) { this.queue = queue; this.threadPool = threadPool; this.distributor = distributor; this.store = store; this.formatter = formatter; this.schedulingProvider = schedulingProvider; this.log = logFactory.Scope("PersistentCommandDispatcher"); Initialize(); }
public JsonLocalStorage(FormatterContainer formatters, IJSRuntime jsRuntime, ILogFactory logFactory, string key) { Ensure.NotNull(formatters, "formatters"); Ensure.NotNull(jsRuntime, "jsRuntime"); Ensure.NotNull(logFactory, "logFactory"); Ensure.NotNullOrEmpty(key, "key"); this.formatters = formatters; this.jsRuntime = jsRuntime; this.log = logFactory.Scope(GetType().Name); this.key = key; }
public HttpQueryDispatcher(ApiClient api, FormatterContainer formatters, ILogFactory logFactory, IEnumerable <IMiddleware> middlewares) { Ensure.NotNull(api, "api"); Ensure.NotNull(formatters, "formatters"); Ensure.NotNull(logFactory, "logFactory"); Ensure.NotNull(middlewares, "middlewares"); this.api = api; this.formatters = formatters; this.middlewares = middlewares; this.log = logFactory.Scope("HttpQueryDispatcher"); }
private void Logging() { ILogFilter logFilter = DefaultLogFilter.Debug; #if !DEBUG logFilter = DefaultLogFilter.Warning; #endif logFactory = new DefaultLogFactory("Root") .AddSerializer(new ConsoleSerializer(new DefaultLogFormatter(), logFilter)); errorLog = logFactory.Scope("Error"); }
public ServerConnectionState(NetworkState network, IApiHubState hub, ExceptionHandlerBuilder exceptionHandlers, ILogFactory logFactory) { Ensure.NotNull(network, "network"); Ensure.NotNull(hub, "hub"); Ensure.NotNull(exceptionHandlers, "exceptionHandlers"); Ensure.NotNull(logFactory, "logFactory"); this.network = network; this.hub = hub; this.log = logFactory.Scope("ServerConnectionState"); network.StatusChanged += OnNetworkChanged; hub.Changed += OnServerStateChanged; exceptionHandlers.Handler <ServerNotRespondingException>(OnServerNotRespondingException); }
public ApiAuthenticationStateProvider(IEventDispatcher events, HttpClient http, TokenContainer token, Interop interop, ILogFactory logFactory, IEnumerable <ITokenValidator> validators) { Ensure.NotNull(events, "eventDispatcher"); Ensure.NotNull(http, "http"); Ensure.NotNull(token, "token"); Ensure.NotNull(interop, "interop"); Ensure.NotNull(logFactory, "logFactory"); Ensure.NotNull(validators, "validators"); this.events = events; this.http = http; this.token = token; this.interop = interop; this.log = logFactory.Scope("ApiAuthenticationState"); this.validators.AddRange(validators); }
public FileSystemWatcherSearchService(string directoryPath, IPinStateService pinStateService, IBackgroundContext backgroundContext, ILogFactory logFactory, IExceptionHandler backgroundExceptionHandler) { Ensure.Condition.DirectoryExists(directoryPath, "directoryPath"); Ensure.NotNull(pinStateService, "pinStateService"); Ensure.NotNull(backgroundContext, "backgroundContext"); Ensure.NotNull(logFactory, "logFactory"); Ensure.NotNull(backgroundExceptionHandler, "backgroundExceptionHandler"); this.directoryPath = directoryPath; this.pinStateService = pinStateService; this.backgroundContext = backgroundContext; this.log = logFactory.Scope("FileSystemWatcherSearch"); this.backgroundExceptionHandler = backgroundExceptionHandler; this.matcherFactory = new PatternMatcherFactory(log.Factory); this.watchers = new List <FileSystemWatcher>(); }
public ApiHubService(BrowserEventDispatcher events, BrowserExceptionHandler exceptions, IOptions <ApiConfiguration> apiConfiguration, TokenContainer token, ILogFactory logFactory) { Ensure.NotNull(events, "events"); Ensure.NotNull(exceptions, "exceptions"); Ensure.NotNull(apiConfiguration, "apiConfiguration"); Ensure.NotNull(token, "token"); Ensure.NotNull(logFactory, "logFactory"); this.events = events; this.exceptions = exceptions; this.apiConfiguration = apiConfiguration.Value; this.token = token; this.log = logFactory.Scope("ApiHub"); this.eventLog = log.Factory.Scope("Events"); this.exceptionLog = log.Factory.Scope("Exceptions"); }
/// <summary> /// Creates new instance. /// </summary> /// <param name="distributor">The command-to-the-queue distributor.</param> /// <param name="store">The publishing store for command persistent delivery.</param> /// <param name="formatter">The formatter for serializing commands.</param> /// <param name="schedulingProvider">The provider of a delay computation for delayed commands.</param> public PersistentCommandDispatcher(ICommandDistributor distributor, ICommandPublishingStore store, ISerializer formatter, ISchedulingProvider schedulingProvider, ILogFactory logFactory) { Ensure.NotNull(distributor, "distributor"); Ensure.NotNull(store, "store"); Ensure.NotNull(formatter, "formatter"); Ensure.NotNull(schedulingProvider, "schedulingProvider"); Ensure.NotNull(logFactory, "logFactory"); this.queue = new TreeQueue(); this.threadPool = new TreeQueueThreadPool(queue); this.distributor = distributor; this.store = store; this.formatter = formatter; this.schedulingProvider = schedulingProvider; this.log = logFactory.Scope("PersistentCommandDispatcher"); Initialize(); }
/// <summary> /// Creates new instance. /// </summary> /// <param name="store">A publishing store for command persistent delivery.</param> /// <param name="schedulingProvider">A provider of a delay computation for delayed events.</param> /// <param name="logFactory">A log factory.</param> public PersistentEventDispatcher(IEventPublishingStore store, ISchedulingProvider schedulingProvider, ILogFactory logFactory) { Ensure.NotNull(store, "store"); Ensure.NotNull(schedulingProvider, "schedulingProvider"); this.store = store; this.schedulingProvider = schedulingProvider; this.log = logFactory.Scope("PersistentEventDispatcher"); EventExceptionHandlers = new DefaultExceptionHandlerCollection(); DispatcherExceptionHandlers = new DefaultExceptionHandlerCollection(); this.descriptorProvider = new HandlerDescriptorProvider( typeof(IEventHandler <>), typeof(IEventHandlerContext <>), TypeHelper.MethodName <IEventHandler <object>, object, Task>(h => h.HandleAsync), EventExceptionHandlers, DispatcherExceptionHandlers ); Handlers = new HandlerCollection(log.Factory, storage, descriptorProvider); }
public ApiClient(ApiVersionChecker versionChecker, HttpClient http, CommandMapper commandMapper, QueryMapper queryMapper, IExceptionHandler exceptionHandler, ApiAuthenticationStateProvider authenticationState, ILogFactory logFactory, Json json, FormatterContainer formatters) { Ensure.NotNull(versionChecker, "versionChecker"); Ensure.NotNull(http, "http"); Ensure.NotNull(commandMapper, "commandMapper"); Ensure.NotNull(queryMapper, "queryMapper"); Ensure.NotNull(exceptionHandler, "exceptionHandler"); Ensure.NotNull(authenticationState, "authenticationState"); Ensure.NotNull(logFactory, "logFactory"); Ensure.NotNull(json, "json"); Ensure.NotNull(formatters, "formatters"); this.versionChecker = versionChecker; this.http = http; this.commandMapper = commandMapper; this.queryMapper = queryMapper; this.exceptionHandler = exceptionHandler; this.authenticationState = authenticationState; this.log = logFactory.Scope("ApiClient"); this.json = json; this.formatters = formatters; }
public ApiClient(IOptions <ApiClientConfiguration> configuration, ApiVersionChecker versionChecker, HttpClient http, CommandMapper commandMapper, QueryMapper queryMapper, IExceptionHandler exceptionHandler, ApiAuthenticationStateProvider authenticationState, ILogFactory logFactory, Json json) { Ensure.NotNull(configuration, "configuration"); Ensure.NotNull(versionChecker, "versionChecker"); Ensure.NotNull(http, "http"); Ensure.NotNull(commandMapper, "commandMapper"); Ensure.NotNull(queryMapper, "queryMapper"); Ensure.NotNull(exceptionHandler, "exceptionHandler"); Ensure.NotNull(authenticationState, "authenticationState"); Ensure.NotNull(logFactory, "logFactory"); Ensure.NotNull(json, "json"); this.versionChecker = versionChecker; this.http = http; this.commandMapper = commandMapper; this.queryMapper = queryMapper; this.exceptionHandler = exceptionHandler; this.authenticationState = authenticationState; this.log = logFactory.Scope("ApiClient"); this.json = json; this.http.BaseAddress = configuration.Value.ApiUrl; }
public void Initialize() { logFactory = new DefaultLogFactory("Root").AddSerializer(new ConsoleSerializer()); errorLog = logFactory.Scope("Error"); readModelContextFactory = Factory.Getter(() => new ReadModelContext(connectionStrings.ReadModel)); eventSourcingContextFactory = Factory.Getter(() => new EventSourcingContext(connectionStrings.EventSourcing)); CreateReadModelContext(); CreateEventSourcingContext(); exceptionHandlerBuilder = new ExceptionHandlerBuilder(); services .AddSingleton(readModelContextFactory) .AddSingleton(eventSourcingContextFactory) .AddSingleton(exceptionHandlerBuilder) .AddSingleton <IExceptionHandler>(exceptionHandlerBuilder); Domain(); priceCalculator = new PriceCalculator(eventDispatcher.Handlers, queryDispatcher); services .AddSingleton(priceCalculator) .AddSingleton(new FormatterContainer(commandFormatter, eventFormatter, queryFormatter, exceptionFormatter)); ReadModels(); services .AddSingleton <IEventHandlerCollection>(eventDispatcher.Handlers) .AddScoped <ICommandDispatcher>(provider => new UserCommandDispatcher(commandDispatcher, provider.GetService <IHttpContextAccessor>().HttpContext, provider.GetService <ApiHub>())) .AddScoped <IQueryDispatcher>(provider => new UserQueryDispatcher(queryDispatcher, provider.GetService <IHttpContextAccessor>().HttpContext)); CurrencyCache currencyCache = new CurrencyCache(eventDispatcher.Handlers, queryDispatcher, queryDispatcher); services .AddSingleton(currencyCache); }
public CompositeListFormatter(ICompositeTypeProvider provider, IFactory <ICompositeStorage> storageFactory, ILogFactory logFactory) { log = logFactory.Scope("CompositeListFormatter"); inner = new Formatter(provider, storageFactory, log); }
private CompositeType BuildType(Type type) { ILog log = logFactory.Scope("BuildType"); string typeName = type.FullName; log.Info("Building type '{0}'.", typeName); CompositeTypeAttribute typeAttribute = type.GetTypeInfo().GetCustomAttribute <CompositeTypeAttribute>(); if (typeAttribute != null) { typeName = typeAttribute.Name; } Dictionary <int, ConstructorInfo> constructors = GetConstructors(type); log.Info("Constructors '{0}'.", constructors.Count); IEnumerable <PropertyDescriptor> properties = GetProperties(type); log.Info("Properties '{0}'.", properties.Count()); List <CompositeVersion> versions = new List <CompositeVersion>(); foreach (KeyValuePair <int, ConstructorInfo> constructor in constructors) { IEnumerable <PropertyDescriptor> versionProperties; // Create version from annotated properties. if (TryFindAnnotatedProperties(properties, constructor.Value.GetParameters().Length, constructor.Key, out versionProperties)) { log.Info("Version '{0}' from annotated properties.", constructor.Key); versions.Add(BuildVersion(constructor.Key, constructor.Value, versionProperties)); continue; } // Create version from property name match. if (TryFindNamedProperties(properties, constructor.Value.GetParameters(), out versionProperties)) { log.Info("Version '{0}' from conventionally properties.", constructor.Key); versions.Add(BuildVersion(constructor.Key, constructor.Value, versionProperties)); continue; } throw new MismatchVersionConstructorException(type, constructor.Key); } CompositeProperty versionProperty = null; PropertyDescriptor versionPropertyDescriptor = properties.FirstOrDefault(p => p.PropertyInfo.GetCustomAttribute <CompositeVersionAttribute>() != null); if (versionPropertyDescriptor == null) { if (versions.Count == 1) { log.Info("Implicit version property."); versionProperty = new CompositeProperty(0, "_Version", typeof(int), model => 1); } else { log.Warning("Found '{0}' versions on the '{1}'.", versions.Count, typeName); throw new MissingVersionPropertyException(type); } } else { Func <object, object> getter = delegateFactory.CreatePropertyGetter(versionPropertyDescriptor.PropertyInfo); // Use setter for version only when setter method is present and is public. Action <object, object> setter = null; if (versionPropertyDescriptor.PropertyInfo.CanWrite && versionPropertyDescriptor.PropertyInfo.SetMethod != null && versionPropertyDescriptor.PropertyInfo.SetMethod.IsPublic) { setter = delegateFactory.CreatePropertySetter(versionPropertyDescriptor.PropertyInfo); } if (setter == null) { versionProperty = new CompositeProperty(0, versionPropertyDescriptor.PropertyInfo.Name, versionPropertyDescriptor.PropertyInfo.PropertyType, getter); } else { versionProperty = new CompositeProperty(0, versionPropertyDescriptor.PropertyInfo.Name, versionPropertyDescriptor.PropertyInfo.PropertyType, getter, setter); } } versions.Sort((v1, v2) => v1.Version.CompareTo(v2.Version)); return(new CompositeType(typeName, type, versions, versionProperty)); }
public TryWriteToLogCommand(ILogFactory logFactory) { Ensure.NotNull(logFactory, "logFactory"); this.log = logFactory.Scope("TryWriteToLog"); }