Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(913)

Side by Side Diff: Src/GoogleApis.DotNet4/Apis/Logging/TraceSourceLogger.cs

Issue 183680043: Issue 501 - Improve the logging, provide TraceSource logger Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: Created 9 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Src/GoogleApis.DotNet4/GoogleApis.DotNet4.csproj » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 Copyright 2014 Google Inc
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 using System;
18 using System.Diagnostics;
19 using System.Threading;
20
21 namespace Google.Apis.Logging
22 {
23 /// <summary>A logger implementation using <see cref="System.Diagnostics.Tra ceSource"/>.</summary>
24 public class TraceSourceLogger : ILogger
25 {
26 private readonly TraceSource TraceSource;
27
28 /// <summary>A default instance of trace source logger.</summary>
29 public static ILogger Default = new TraceSourceLogger();
30
31 /// <summary>Creates a new instance of the trace source logger using "go ogle-api-dotnet-client".</summary>
32 private TraceSourceLogger()
33 {
34 TraceSource = new TraceSource("google-api-dotnet-client");
35 }
36
37 /// <summary>Creates a new instance of trace source logger using the giv en type.</summary>
38 public TraceSourceLogger(Type t)
39 {
40 TraceSource = new TraceSource(t.FullName);
41 }
42
43 public bool IsDebugEnabled
44 {
45 get { return true; }
46 }
47
48 public ILogger ForType(Type type)
49 {
50 return new TraceSourceLogger(type);
51 }
52
53 public ILogger ForType<T>()
54 {
55 return new TraceSourceLogger(typeof(T));
56 }
57
58 public void Info(string message, params object[] formatArgs)
59 {
60 TraceEvent(TraceEventType.Information, message, formatArgs);
61 }
62
63 public void Warning(string message, params object[] formatArgs)
64 {
65 TraceEvent(TraceEventType.Warning, message, formatArgs);
66 }
67
68 public void Debug(string message, params object[] formatArgs)
69 {
70 TraceEvent(TraceEventType.Verbose, message, formatArgs);
71 }
72
73 public void Error(Exception exception, string message, params object[] f ormatArgs)
74 {
75 TraceEvent(TraceEventType.Warning, message, formatArgs);
76 TraceEvent(TraceEventType.Warning, "Exception is: ", exception.Messa ge);
77 }
78
79 public void Error(string message, params object[] formatArgs)
80 {
81 TraceEvent(TraceEventType.Warning, message, formatArgs);
82 }
83
84 /// <summary>Traces the event using the current thread id.</summary>
85 public void TraceEvent(TraceEventType type, string msg, params object[] args)
86 {
87 TraceSource.TraceEvent(type, Thread.CurrentThread.ManagedThreadId, m sg, args);
88 }
89 }
90 }
91
OLDNEW
« no previous file with comments | « no previous file | Src/GoogleApis.DotNet4/GoogleApis.DotNet4.csproj » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b