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

Side by Side Diff: Src/GoogleApis.Tools.CodeGen/Decorator/ResourceDecorator/Log4NetResourceDecorator.cs

Issue 12020043: Issue 325 - Remove discovery and codegen (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: Sir miceli comment Created 10 years, 7 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
OLDNEW
(Empty)
1 /*
2 Copyright 2010 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.CodeDom;
19 using System.Collections.Generic;
20 using Google.Apis.Discovery;
21 using Google.Apis.Logging;
22 using Google.Apis.Tools.CodeGen.Generator;
23
24 namespace Google.Apis.Tools.CodeGen.Decorator.ResourceDecorator
25 {
26 /// <summary>
27 /// An optional decorator that adds logging to the Resoruces as they are cal led.
28 /// This uses log4Net as the logging framework.
29 /// </summary>
30 [Obsolete("Logging is now done within the core library.")]
31 public class Log4NetResourceDecorator : IResourceDecorator
32 {
33 public const string LoggerName = "logger";
34 private static readonly ILogger logger = ApplicationContext.Logger.ForTy pe<Log4NetResourceDecorator>();
35
36 #region IResourceDecorator Members
37
38 public void DecorateClass(IResource resource,
39 string className,
40 CodeTypeDeclaration resourceClass,
41 ResourceClassGenerator generator,
42 string serviceClassName,
43 IEnumerable<IResourceDecorator> allDecorators)
44 {
45 //public static log4net.ILog Logger = log4net.LogManager.GetLogger(t ypeof(<className>));
46 logger.Debug("Adding logger to ResourceClass.");
47 var loggerField = new CodeMemberField("log4net.ILog", LoggerName);
48 var initialiser = new CodeMethodInvokeExpression();
49 initialiser.Method = new CodeMethodReferenceExpression(
50 new CodeTypeReferenceExpression("log4net.LogManager"), "GetLogge r");
51 initialiser.Parameters.Add(new CodeTypeOfExpression(className));
52 loggerField.InitExpression = initialiser;
53
54 resourceClass.Members.Add(loggerField);
55 }
56
57 public void DecorateMethodBeforeExecute(IResource resource, IMethod meth od, CodeMemberMethod codeMember)
58 {
59 var logCall = new CodeMethodInvokeExpression();
60 logCall.Method = new CodeMethodReferenceExpression(new CodeVariableR eferenceExpression(LoggerName), "Debug");
61 logCall.Parameters.Add(
62 new CodePrimitiveExpression(String.Format("Executing {0}.{1}", r esource.Name, method.Name)));
63 codeMember.Statements.Add(logCall);
64 }
65
66 public void DecorateMethodAfterExecute(IResource resource, IMethod metho d, CodeMemberMethod codeMember)
67 {
68 var logCall = new CodeMethodInvokeExpression();
69 logCall.Method = new CodeMethodReferenceExpression(new CodeVariableR eferenceExpression(LoggerName), "Debug");
70 logCall.Parameters.Add(
71 new CodePrimitiveExpression(String.Format("Done Executing {0}.{1 }", resource.Name, method.Name)));
72 codeMember.Statements.Add(logCall);
73 }
74
75 #endregion
76 }
77 }
OLDNEW

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