Skip to content

TypeScript project that shows how one could implement tracing and logging in JavaScript / TypeScript

License

Notifications You must be signed in to change notification settings

webbes/TracingAndLogging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tracing & Logging

TypeScript project that shows how one could implement tracing and logging in JavaScript / TypeScript

The design is based on the .Net System.Diagnostics namespace and contains 3 TraceListeners:

  • ConsoleLogTraceListener
  • ModalTraceListener
  • ApplicationInsightsTraceListener

Build/run/debug

To build/run/debug in Visual Studio you can hit F5, to build/run/debug in Visual Studio Code you can run the following commands in the integrated terminal:

  • npm install
  • npm start

You can then hit F5 to start debugging in Chrome.

Use

You can use the static Trace class methods anywhere in your application:

import { Trace } from "Diagnostics/Trace";

Trace.Info("Tracing Information.");
Trace.Error("Tracing Error.");
Trace.Warning("Tracing Warning.");
Trace.Verbose("Tracing Verbose.");

Configuration

You can configure the trace listeners (preferably on application start) like this:

import { Trace } from "Diagnostics/Trace";
import { TraceLevelFilter } from "Diagnostics/TraceLevelFilter";
import { QueryStringFilter } from "Diagnostics/QueryStringFilter";
import { TraceSource } from "Diagnostics/TraceSource";
import { TraceLevel } from "Diagnostics/TraceLevel";
import { ConsoleLogTraceListener } from "Diagnostics/ConsoleLogTraceListener";
import { ModalTraceListener } from "Diagnostics/ModalTraceListener";
import { ApplicationInsightsTraceListener } from "Diagnostics/ApplicationInsightsTraceListener";

Trace.TraceSources.push(
    new TraceSource(new QueryStringFilter(),
        new ConsoleLogTraceListener(new TraceLevelFilter(TraceLevel.Verbose)),
        new ModalTraceListener(new TraceLevelFilter(TraceLevel.Error)),
        new ApplicationInsightsTraceListener(new TraceLevelFilter(TraceLevel.Verbose),
            "b4989aa1-c6ce-47f1-8c4c-00cd9cd1ace9")
    ));

About

TypeScript project that shows how one could implement tracing and logging in JavaScript / TypeScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published