// REVIEW: Important that this object + ThreadProc has NO reference to the parent BackgroundMultiLogWriter. // If there were a reference from this, it would never finalize. public BackgroundThread(ITracerFactory setupTracerFactory, ConcurrentQueue <Action> backgroundActionQueue) { Contract.Requires <ArgumentNullException>(setupTracerFactory != null); Contract.Requires <ArgumentNullException>(backgroundActionQueue != null); _tracer = setupTracerFactory.TracerFor(this); _backgroundActionQueue = backgroundActionQueue; }
internal static void SafeStop(this IStartable startable, ITracerFactory tracerFactory) { Contract.Requires <ArgumentNullException>(tracerFactory != null); if (startable == null) { return; } Tracer tracer = tracerFactory.TracerFor(startable); SafeStop(startable, tracer); }
internal static void SafeDispose(this IDisposable disposable, ITracerFactory tracerFactory) { Contract.Requires <ArgumentNullException>(tracerFactory != null); if (disposable == null) { return; } Tracer tracer = tracerFactory.TracerFor(disposable); disposable.SafeDispose(tracer); }
internal BackgroundMultiLogWriter(ITracerFactory setupTracerFactory) { Contract.Requires <ArgumentNullException>(setupTracerFactory != null); _setupTracerFactory = setupTracerFactory; _tracer = setupTracerFactory.TracerFor(this); _proxyLogWriters = new List <LogWriterProxy>(); _proxyEntryWriters = new List <object>(); _backgroundActionQueue = new ConcurrentQueue <Action>(); _backgroundThread = null; }
/// <summary> /// Initialize the <see cref="FormatWriter" />. /// </summary> /// <param name="setupTracerFactory">The <see cref="ITracerFactory" /> to use for logging setup operations.</param> /// <param name="fieldDelimiter">The field delimiter for formatted text output.</param> /// <param name="spacesPerIndentLevel">The number of spaces per indent level. Can be 0 for no indenting.</param> protected FormatWriter(ITracerFactory setupTracerFactory, string fieldDelimiter = DefaultFieldDelimiter, int spacesPerIndentLevel = DefaultSpacesPerIndent) { Contract.Requires <ArgumentNullException>(setupTracerFactory != null); Contract.Requires <ArgumentNullException>(fieldDelimiter != null); setupTracer = setupTracerFactory.TracerFor(this); _fieldDelimiter = fieldDelimiter; SpacesPerIndent = spacesPerIndentLevel; _markupBuffer = new StringBuilder(256); _fieldBuffer = new StringBuilder(512); _startedEntries = 0; // Set defaults IncludeTime = true; IncludeDate = false; }
/// <summary> /// Returns a new <see cref="TestServer"/>, configured with WebApp.Web startup code. /// Requests against the test server are processed directly in memory without going over the network. /// </summary> /// <param name="iocModule">Configures the odata model for the test in SimpleInjector</param> /// <param name="odataConfigAction">Optional configuration for <see cref="ODataServerConfigurer"/>.</param> /// <returns></returns> /// <remarks> /// Note that the returned <see cref="TestServer"/> should be disposed. /// </para> /// </remarks> protected TestServer CreateTestServer(IModule iocModule, Action <ODataServerConfigurer> odataConfigAction = null) { // Setup the DI container Container container = new Container { Options = { AllowOverridingRegistrations = true } }; container.RegisterModules(new ODataServiceModule(), iocModule); var testServer = TestServer.Create(owinAppBuilder => ConfigureOwinPipeline(owinAppBuilder, container, odataConfigAction)); // Ensure logging setup is healthy _tracerFactory.TracerFor(this).Info("Test OData server started..."); Assert.True(_logManager.IsHealthy); return(testServer); }
public HttpLoggingMiddleware(OwinMiddleware next, LogManager logManager, ITracerFactory tracerFactory) : base(next) { Contract.Requires <ArgumentNullException>(next != null); Contract.Requires <ArgumentNullException>(logManager != null); Contract.Requires <ArgumentNullException>(tracerFactory != null); _requestCounter = 0L; _setupTracer = logManager.SetupTracerFactory.TracerFor(this); _requestEntryWriter = logManager.GetEntryWriter <HttpRequestEntry>(); _responseEntryWriter = logManager.GetEntryWriter <HttpResponseEntry>(); const string startedMessage = "OWIN HTTP logging started."; _setupTracer.Info(startedMessage); _tracer = tracerFactory.TracerFor(this); _tracer.Info(startedMessage); }
/// <inheritdoc /> public override void Write(ref TraceEntry entry) { if (IsTraceEnabled(entry.TracerName, entry.TraceLevel)) { try { InnerEntryWriter.Write(ref entry); } catch (Exception excp) { if (1 == Interlocked.Increment(ref _countWritingExceptions)) { // TODO: Replace this with status polling if (_setupTracerFactory != null) { _setupTracerFactory.TracerFor(this).Error(excp, "At least one exception occurred while writing trace entyrs to " + InnerEntryWriter); } } } } }
/// <summary> /// Creates a new <see cref="LogJamExceptionLogger" />, which logs Web API exceptions to a <see cref="Tracer" /> obtained /// from /// <paramref name="tracerFactory" />. /// </summary> /// <param name="tracerFactory">A <see cref="ITracerFactory" />.</param> public LogJamExceptionLogger(ITracerFactory tracerFactory) { Contract.Requires <ArgumentNullException>(tracerFactory != null); _tracer = tracerFactory.TracerFor(this); }