Created
November 15, 2017 04:15
-
-
Save jpda/ee37dc029d157efb907525f27ee399f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Runtime.CompilerServices; | |
| using Microsoft.ApplicationInsights; | |
| using Microsoft.ApplicationInsights.DataContracts; | |
| namespace Stuff | |
| { | |
| public class Log | |
| { | |
| private readonly TelemetryClient _tc; | |
| internal Log(TelemetryClient tc) | |
| { | |
| _tc = tc; | |
| } | |
| public void Flush() | |
| { | |
| _tc.Flush(); | |
| } | |
| public void Debug(string message, [CallerMemberName] string caller = "") | |
| { | |
| _tc.TrackTrace($"{caller}: {message}", SeverityLevel.Verbose); | |
| } | |
| public void Debug(string message, IDictionary<string, string> props, [CallerMemberName] string caller = "") | |
| { | |
| _tc.TrackTrace($"{caller}: {message}", SeverityLevel.Verbose, props); | |
| } | |
| public void Error(Exception ex, [CallerMemberName] string caller = "") | |
| { | |
| _tc.TrackException(ex); | |
| //_tc.TrackTrace(ex.Message, SeverityLevel.Critical); | |
| } | |
| public void Error(string message, [CallerMemberName] string caller = "") | |
| { | |
| _tc.TrackTrace($"{caller}: {message}", SeverityLevel.Error); | |
| } | |
| public void Event(string name, IDictionary<string, string> props = null, IDictionary<string, double> metric = null) | |
| { | |
| _tc.TrackEvent(name, props, metric); | |
| } | |
| public void Request(string name, DateTimeOffset startTime, TimeSpan duration) | |
| { | |
| _tc.TrackRequest(name, startTime, duration, "OK", true); | |
| } | |
| public void FailedRequest(string name, DateTimeOffset startTime, TimeSpan duration) | |
| { | |
| _tc.TrackRequest(name, startTime, duration, "OK", false); | |
| } | |
| public void Info(string message, [CallerMemberName] string caller = "") | |
| { | |
| _tc.TrackTrace($"{caller}: {message}", SeverityLevel.Information); | |
| } | |
| public void Warn(string message, [CallerMemberName] string caller = "") | |
| { | |
| _tc.TrackTrace($"{caller}: {message}", SeverityLevel.Warning); | |
| } | |
| public void Critical(string message, [CallerMemberName] string caller = "") | |
| { | |
| _tc.TrackTrace($"{caller}: {message}", SeverityLevel.Critical); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment