##// END OF EJS Templates
Added class Trace<T> to manage channels for individual classes, if SomeClass...
cin -
r212:a01d9df88d74 v2
parent child
Show More
@@ -0,0 +1,74
1 using System;
2 using System.Collections.Generic;
3 using System.Diagnostics;
4 using System.Linq;
5 using System.Text;
6 using System.Threading.Tasks;
7
8 namespace Implab.Diagnostics {
9 public static class Trace<T> {
10
11 readonly static LogChannel<TraceEvent> _channel = new LogChannel<TraceEvent>(typeof(T).Name);
12
13 public static LogChannel<TraceEvent> Channel {
14 get { return _channel; }
15 }
16
17 /// <summary>
18 /// Starts the logical operation nested to the current operation nested to the current one.
19 /// </summary>
20 [Conditional("TRACE")]
21 public static void StartLogicalOperation() {
22 TraceContext.Instance.StartLogicalOperation();
23
24 }
25
26 /// <summary>
27 /// Starts the logical operation with the specified name, this name is usefull in logs.
28 /// </summary>
29 /// <param name="name">Name.</param>
30 [Conditional("TRACE")]
31 public static void StartLogicalOperation(string name) {
32 TraceContext.Instance.StartLogicalOperation(name);
33 }
34
35 /// <summary>
36 /// Ends the logical operation and restores the previous one.
37 /// </summary>
38 [Conditional("TRACE")]
39 public static void EndLogicalOperation() {
40 var op = TraceContext.Instance.EndLogicalOperation();
41 LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(op, TraceEventType.OperationCompleted, String.Format("-{0} : {1}ms", op.Name, op.Duration)));
42 }
43
44 /// <summary>
45 /// Writes an informational message.
46 /// </summary>
47 /// <param name="format">Format.</param>
48 /// <param name="arguments">Arguments.</param>
49 [Conditional("TRACE")]
50 public static void Log(string format, params object[] arguments) {
51 Channel.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, TraceEventType.Information, format, arguments));
52 }
53
54 /// <summary>
55 /// Writes a warning message.
56 /// </summary>
57 /// <param name="format">Format.</param>
58 /// <param name="arguments">Arguments.</param>
59 [Conditional("TRACE")]
60 public static void Warn(string format, params object[] arguments) {
61 Channel.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, TraceEventType.Warning, format, arguments));
62 }
63
64 [Conditional("TRACE")]
65 public static void Error(string format, params object[] arguments) {
66 Channel.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, TraceEventType.Error, format, arguments));
67 }
68
69 [Conditional("TRACE")]
70 public static void Error(Exception err) {
71 Error("{0}", err);
72 }
73 }
74 }
@@ -0,0 +1,10
1 using System;
2
3 namespace Implab.Diagnostics {
4 /// <summary>
5 /// Used to mark class which uses <see cref="Trace{T}"/> class to trace it's events
6 /// </summary>
7 [AttributeUsage(AttributeTargets.Class)]
8 public class TraceSourceAttribute : Attribute {
9 }
10 }
@@ -1,275 +1,277
1 1 ο»Ώ<?xml version="1.0" encoding="utf-8"?>
2 2 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 3 <PropertyGroup>
4 4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5 5 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6 6 <ProjectGuid>{F550F1F8-8746-4AD0-9614-855F4C4B7F05}</ProjectGuid>
7 7 <OutputType>Library</OutputType>
8 8 <RootNamespace>Implab</RootNamespace>
9 9 <AssemblyName>Implab</AssemblyName>
10 10 <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
11 11 <ReleaseVersion>0.2</ReleaseVersion>
12 12 <ProductVersion>8.0.30703</ProductVersion>
13 13 <SchemaVersion>2.0</SchemaVersion>
14 14 </PropertyGroup>
15 15 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16 16 <DebugSymbols>true</DebugSymbols>
17 17 <DebugType>full</DebugType>
18 18 <Optimize>false</Optimize>
19 19 <OutputPath>bin\Debug</OutputPath>
20 20 <DefineConstants>TRACE;DEBUG;</DefineConstants>
21 21 <ErrorReport>prompt</ErrorReport>
22 22 <WarningLevel>4</WarningLevel>
23 23 <ConsolePause>false</ConsolePause>
24 24 <RunCodeAnalysis>true</RunCodeAnalysis>
25 25 </PropertyGroup>
26 26 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27 27 <DebugType>full</DebugType>
28 28 <Optimize>true</Optimize>
29 29 <OutputPath>bin\Release</OutputPath>
30 30 <ErrorReport>prompt</ErrorReport>
31 31 <WarningLevel>4</WarningLevel>
32 32 <ConsolePause>false</ConsolePause>
33 33 </PropertyGroup>
34 34 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug 4.5|AnyCPU' ">
35 35 <DebugSymbols>true</DebugSymbols>
36 36 <DebugType>full</DebugType>
37 37 <Optimize>false</Optimize>
38 38 <OutputPath>bin\Debug</OutputPath>
39 39 <DefineConstants>TRACE;DEBUG;NET_4_5</DefineConstants>
40 40 <ErrorReport>prompt</ErrorReport>
41 41 <WarningLevel>4</WarningLevel>
42 42 <RunCodeAnalysis>true</RunCodeAnalysis>
43 43 <ConsolePause>false</ConsolePause>
44 44 </PropertyGroup>
45 45 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release 4.5|AnyCPU' ">
46 46 <Optimize>true</Optimize>
47 47 <OutputPath>bin\Release</OutputPath>
48 48 <ErrorReport>prompt</ErrorReport>
49 49 <WarningLevel>4</WarningLevel>
50 50 <ConsolePause>false</ConsolePause>
51 51 <DefineConstants>NET_4_5</DefineConstants>
52 52 </PropertyGroup>
53 53 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|AnyCPU' ">
54 54 <DebugSymbols>true</DebugSymbols>
55 55 <DebugType>full</DebugType>
56 56 <Optimize>false</Optimize>
57 57 <OutputPath>bin\Debug</OutputPath>
58 58 <DefineConstants>TRACE;DEBUG;NET_4_5;MONO</DefineConstants>
59 59 <ErrorReport>prompt</ErrorReport>
60 60 <WarningLevel>4</WarningLevel>
61 61 <RunCodeAnalysis>true</RunCodeAnalysis>
62 62 <ConsolePause>false</ConsolePause>
63 63 </PropertyGroup>
64 64 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMono|AnyCPU' ">
65 65 <Optimize>true</Optimize>
66 66 <OutputPath>bin\Release</OutputPath>
67 67 <DefineConstants>NET_4_5;MONO;</DefineConstants>
68 68 <ErrorReport>prompt</ErrorReport>
69 69 <WarningLevel>4</WarningLevel>
70 70 <ConsolePause>false</ConsolePause>
71 71 </PropertyGroup>
72 72 <ItemGroup>
73 73 <Reference Include="System" />
74 74 <Reference Include="System.Xml" />
75 75 <Reference Include="mscorlib" />
76 76 </ItemGroup>
77 77 <ItemGroup>
78 78 <Compile Include="Components\StateChangeEventArgs.cs" />
79 79 <Compile Include="CustomEqualityComparer.cs" />
80 80 <Compile Include="Diagnostics\ConsoleTraceListener.cs" />
81 81 <Compile Include="Diagnostics\LogChannel.cs" />
82 82 <Compile Include="Diagnostics\LogicalOperation.cs" />
83 83 <Compile Include="Diagnostics\TextFileListener.cs" />
84 <Compile Include="Diagnostics\Trace.cs" />
84 85 <Compile Include="Diagnostics\TraceLog.cs" />
85 86 <Compile Include="Diagnostics\TraceEvent.cs" />
86 87 <Compile Include="Diagnostics\TraceEventType.cs" />
88 <Compile Include="Diagnostics\TraceSourceAttribute.cs" />
87 89 <Compile Include="ICancellable.cs" />
88 90 <Compile Include="IProgressHandler.cs" />
89 91 <Compile Include="IProgressNotifier.cs" />
90 92 <Compile Include="IPromiseT.cs" />
91 93 <Compile Include="IPromise.cs" />
92 94 <Compile Include="IServiceLocator.cs" />
93 95 <Compile Include="ITaskController.cs" />
94 96 <Compile Include="Parallels\DispatchPool.cs" />
95 97 <Compile Include="Parallels\ArrayTraits.cs" />
96 98 <Compile Include="Parallels\MTQueue.cs" />
97 99 <Compile Include="Parallels\WorkerPool.cs" />
98 100 <Compile Include="ProgressInitEventArgs.cs" />
99 101 <Compile Include="Properties\AssemblyInfo.cs" />
100 102 <Compile Include="Parallels\AsyncPool.cs" />
101 103 <Compile Include="Safe.cs" />
102 104 <Compile Include="SyncContextPromise.cs" />
103 105 <Compile Include="ValueEventArgs.cs" />
104 106 <Compile Include="PromiseExtensions.cs" />
105 107 <Compile Include="SyncContextPromiseT.cs" />
106 108 <Compile Include="Diagnostics\OperationContext.cs" />
107 109 <Compile Include="Diagnostics\TraceContext.cs" />
108 110 <Compile Include="Diagnostics\LogEventArgs.cs" />
109 111 <Compile Include="Diagnostics\LogEventArgsT.cs" />
110 112 <Compile Include="Diagnostics\Extensions.cs" />
111 113 <Compile Include="PromiseEventType.cs" />
112 114 <Compile Include="Parallels\AsyncQueue.cs" />
113 115 <Compile Include="PromiseT.cs" />
114 116 <Compile Include="IDeferred.cs" />
115 117 <Compile Include="IDeferredT.cs" />
116 118 <Compile Include="Promise.cs" />
117 119 <Compile Include="PromiseTransientException.cs" />
118 120 <Compile Include="Parallels\Signal.cs" />
119 121 <Compile Include="Parallels\SharedLock.cs" />
120 122 <Compile Include="Diagnostics\ILogWriter.cs" />
121 123 <Compile Include="Diagnostics\ListenerBase.cs" />
122 124 <Compile Include="Parallels\BlockingQueue.cs" />
123 125 <Compile Include="AbstractEvent.cs" />
124 126 <Compile Include="AbstractPromise.cs" />
125 127 <Compile Include="AbstractPromiseT.cs" />
126 128 <Compile Include="FuncTask.cs" />
127 129 <Compile Include="FuncTaskBase.cs" />
128 130 <Compile Include="FuncTaskT.cs" />
129 131 <Compile Include="ActionChainTaskBase.cs" />
130 132 <Compile Include="ActionChainTask.cs" />
131 133 <Compile Include="ActionChainTaskT.cs" />
132 134 <Compile Include="FuncChainTaskBase.cs" />
133 135 <Compile Include="FuncChainTask.cs" />
134 136 <Compile Include="FuncChainTaskT.cs" />
135 137 <Compile Include="ActionTaskBase.cs" />
136 138 <Compile Include="ActionTask.cs" />
137 139 <Compile Include="ActionTaskT.cs" />
138 140 <Compile Include="ICancellationToken.cs" />
139 141 <Compile Include="SuccessPromise.cs" />
140 142 <Compile Include="SuccessPromiseT.cs" />
141 143 <Compile Include="PromiseAwaiterT.cs" />
142 144 <Compile Include="PromiseAwaiter.cs" />
143 145 <Compile Include="Components\ComponentContainer.cs" />
144 146 <Compile Include="Components\Disposable.cs" />
145 147 <Compile Include="Components\DisposablePool.cs" />
146 148 <Compile Include="Components\ObjectPool.cs" />
147 149 <Compile Include="Components\ServiceLocator.cs" />
148 150 <Compile Include="Components\IInitializable.cs" />
149 151 <Compile Include="TaskController.cs" />
150 152 <Compile Include="Components\App.cs" />
151 153 <Compile Include="Components\IRunnable.cs" />
152 154 <Compile Include="Components\ExecutionState.cs" />
153 155 <Compile Include="Components\RunnableComponent.cs" />
154 156 <Compile Include="Components\IFactory.cs" />
155 157 <Compile Include="Automaton\IAlphabet.cs" />
156 158 <Compile Include="Automaton\ParserException.cs" />
157 159 <Compile Include="Automaton\IndexedAlphabetBase.cs" />
158 160 <Compile Include="Automaton\IAlphabetBuilder.cs" />
159 161 <Compile Include="Automaton\RegularExpressions\AltToken.cs" />
160 162 <Compile Include="Automaton\RegularExpressions\BinaryToken.cs" />
161 163 <Compile Include="Automaton\RegularExpressions\CatToken.cs" />
162 164 <Compile Include="Automaton\RegularExpressions\StarToken.cs" />
163 165 <Compile Include="Automaton\RegularExpressions\SymbolToken.cs" />
164 166 <Compile Include="Automaton\RegularExpressions\EmptyToken.cs" />
165 167 <Compile Include="Automaton\RegularExpressions\Token.cs" />
166 168 <Compile Include="Automaton\RegularExpressions\IVisitor.cs" />
167 169 <Compile Include="Automaton\AutomatonTransition.cs" />
168 170 <Compile Include="Formats\JSON\JSONElementContext.cs" />
169 171 <Compile Include="Formats\JSON\JSONElementType.cs" />
170 172 <Compile Include="Formats\JSON\JSONGrammar.cs" />
171 173 <Compile Include="Formats\JSON\JSONParser.cs" />
172 174 <Compile Include="Formats\JSON\JSONScanner.cs" />
173 175 <Compile Include="Formats\JSON\JsonTokenType.cs" />
174 176 <Compile Include="Formats\JSON\JSONWriter.cs" />
175 177 <Compile Include="Formats\JSON\JSONXmlReader.cs" />
176 178 <Compile Include="Formats\JSON\JSONXmlReaderOptions.cs" />
177 179 <Compile Include="Formats\JSON\StringTranslator.cs" />
178 180 <Compile Include="Automaton\MapAlphabet.cs" />
179 181 <Compile Include="Formats\CharAlphabet.cs" />
180 182 <Compile Include="Formats\ByteAlphabet.cs" />
181 183 <Compile Include="Automaton\IDFATable.cs" />
182 184 <Compile Include="Automaton\IDFATableBuilder.cs" />
183 185 <Compile Include="Automaton\DFATable.cs" />
184 186 <Compile Include="Automaton\RegularExpressions\RegularExpressionVisitor.cs" />
185 187 <Compile Include="Automaton\RegularExpressions\ITaggedDFABuilder.cs" />
186 188 <Compile Include="Formats\TextScanner.cs" />
187 189 <Compile Include="Formats\StringScanner.cs" />
188 190 <Compile Include="Formats\ReaderScanner.cs" />
189 191 <Compile Include="Formats\ScannerContext.cs" />
190 192 <Compile Include="Formats\Grammar.cs" />
191 193 <Compile Include="Automaton\RegularExpressions\EndTokenT.cs" />
192 194 <Compile Include="Automaton\RegularExpressions\EndToken.cs" />
193 195 <Compile Include="Automaton\RegularExpressions\RegularExpressionVisitorT.cs" />
194 196 <Compile Include="Automaton\AutomatonConst.cs" />
195 197 <Compile Include="Automaton\RegularExpressions\RegularDFA.cs" />
196 198 <Compile Include="Components\LazyAndWeak.cs" />
197 199 <Compile Include="AbstractTask.cs" />
198 200 <Compile Include="AbstractTaskT.cs" />
199 201 <Compile Include="FailedPromise.cs" />
200 202 <Compile Include="FailedPromiseT.cs" />
201 203 <Compile Include="Components\PollingComponent.cs" />
202 204 </ItemGroup>
203 205 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
204 206 <ItemGroup />
205 207 <ProjectExtensions>
206 208 <MonoDevelop>
207 209 <Properties>
208 210 <Policies>
209 211 <CSharpFormattingPolicy IndentSwitchBody="True" NamespaceBraceStyle="EndOfLine" ClassBraceStyle="EndOfLine" InterfaceBraceStyle="EndOfLine" StructBraceStyle="EndOfLine" EnumBraceStyle="EndOfLine" MethodBraceStyle="EndOfLine" ConstructorBraceStyle="EndOfLine" DestructorBraceStyle="EndOfLine" BeforeMethodDeclarationParentheses="False" BeforeMethodCallParentheses="False" BeforeConstructorDeclarationParentheses="False" NewLineBeforeConstructorInitializerColon="NewLine" NewLineAfterConstructorInitializerColon="SameLine" BeforeIndexerDeclarationBracket="False" BeforeDelegateDeclarationParentheses="False" NewParentheses="False" SpacesBeforeBrackets="False" inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp" />
210 212 <TextStylePolicy FileWidth="120" EolMarker="Unix" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/x-csharp" />
211 213 <DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedHierarchical" ResourceNamePolicy="MSBuild" />
212 214 <TextStylePolicy FileWidth="120" TabsToSpaces="False" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="application/xml" />
213 215 <XmlFormattingPolicy inheritsSet="Mono" inheritsScope="application/xml" scope="application/xml" />
214 216 <TextStylePolicy FileWidth="120" TabsToSpaces="False" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/plain" />
215 217 <NameConventionPolicy>
216 218 <Rules>
217 219 <NamingRule Name="Namespaces" AffectedEntity="Namespace" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
218 220 <NamingRule Name="Types" AffectedEntity="Class, Struct, Enum, Delegate" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
219 221 <NamingRule Name="Interfaces" AffectedEntity="Interface" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
220 222 <RequiredPrefixes>
221 223 <String>I</String>
222 224 </RequiredPrefixes>
223 225 </NamingRule>
224 226 <NamingRule Name="Attributes" AffectedEntity="CustomAttributes" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
225 227 <RequiredSuffixes>
226 228 <String>Attribute</String>
227 229 </RequiredSuffixes>
228 230 </NamingRule>
229 231 <NamingRule Name="Event Arguments" AffectedEntity="CustomEventArgs" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
230 232 <RequiredSuffixes>
231 233 <String>EventArgs</String>
232 234 </RequiredSuffixes>
233 235 </NamingRule>
234 236 <NamingRule Name="Exceptions" AffectedEntity="CustomExceptions" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
235 237 <RequiredSuffixes>
236 238 <String>Exception</String>
237 239 </RequiredSuffixes>
238 240 </NamingRule>
239 241 <NamingRule Name="Methods" AffectedEntity="Methods" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
240 242 <NamingRule Name="Static Readonly Fields" AffectedEntity="ReadonlyField" VisibilityMask="Internal, Protected, Public" NamingStyle="CamelCase" IncludeInstanceMembers="False" IncludeStaticEntities="True" />
241 243 <NamingRule Name="Fields (Non Private)" AffectedEntity="Field" VisibilityMask="Internal, Public" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
242 244 <NamingRule Name="ReadOnly Fields (Non Private)" AffectedEntity="ReadonlyField" VisibilityMask="Internal, Public" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False" />
243 245 <NamingRule Name="Fields (Private)" AffectedEntity="Field, ReadonlyField" VisibilityMask="Private, Protected" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False">
244 246 <RequiredPrefixes>
245 247 <String>m_</String>
246 248 </RequiredPrefixes>
247 249 </NamingRule>
248 250 <NamingRule Name="Static Fields (Private)" AffectedEntity="Field" VisibilityMask="Private" NamingStyle="CamelCase" IncludeInstanceMembers="False" IncludeStaticEntities="True">
249 251 <RequiredPrefixes>
250 252 <String>_</String>
251 253 </RequiredPrefixes>
252 254 </NamingRule>
253 255 <NamingRule Name="ReadOnly Fields (Private)" AffectedEntity="ReadonlyField" VisibilityMask="Private, Protected" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False">
254 256 <RequiredPrefixes>
255 257 <String>m_</String>
256 258 </RequiredPrefixes>
257 259 </NamingRule>
258 260 <NamingRule Name="Constant Fields" AffectedEntity="ConstantField" VisibilityMask="VisibilityMask" NamingStyle="AllUpper" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
259 261 <NamingRule Name="Properties" AffectedEntity="Property" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
260 262 <NamingRule Name="Events" AffectedEntity="Event" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
261 263 <NamingRule Name="Enum Members" AffectedEntity="EnumMember" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
262 264 <NamingRule Name="Parameters" AffectedEntity="Parameter, LocalVariable" VisibilityMask="VisibilityMask" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
263 265 <NamingRule Name="Type Parameters" AffectedEntity="TypeParameter" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
264 266 <RequiredPrefixes>
265 267 <String>T</String>
266 268 </RequiredPrefixes>
267 269 </NamingRule>
268 270 </Rules>
269 271 </NameConventionPolicy>
270 272 </Policies>
271 273 </Properties>
272 274 </MonoDevelop>
273 275 </ProjectExtensions>
274 276 <ItemGroup />
275 277 </Project> No newline at end of file
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

ok, latest stable version should be in default

You need to be logged in to leave comments. Login now