Auto status change to "Under Review"
@@ -0,0 +1,41 | |||||
|
1 | using System; | |||
|
2 | using System.Threading; | |||
|
3 | using System.Threading.Tasks; | |||
|
4 | using Implab.Components; | |||
|
5 | using Implab.Diagnostics; | |||
|
6 | using Xunit; | |||
|
7 | ||||
|
8 | namespace Implab.Test { | |||
|
9 | ||||
|
10 | public class DiagnosticsTest { | |||
|
11 | class Foo {} | |||
|
12 | ||||
|
13 | [Fact] | |||
|
14 | public void TestRegistration() { | |||
|
15 | var channel = TraceSourceChannel<Foo>.Default; | |||
|
16 | ||||
|
17 | Assert.Equal(typeof(Foo), channel.Id); | |||
|
18 | Assert.Equal(typeof(Foo).FullName, channel.Source.Name); | |||
|
19 | ||||
|
20 | TraceSourceChannel found = null; | |||
|
21 | int visited = 0; | |||
|
22 | ||||
|
23 | TraceRegistry.Global.Subscribe(x => { | |||
|
24 | visited++; | |||
|
25 | found = x as TraceSourceChannel; | |||
|
26 | }, false); | |||
|
27 | ||||
|
28 | Assert.Equal(0, visited); | |||
|
29 | ||||
|
30 | TraceRegistry.Global.Subscribe(x => { | |||
|
31 | visited++; | |||
|
32 | found = x as TraceSourceChannel; | |||
|
33 | }, true); | |||
|
34 | ||||
|
35 | Assert.Equal(1,visited); | |||
|
36 | Assert.Equal(channel, found); | |||
|
37 | ||||
|
38 | } | |||
|
39 | ||||
|
40 | } | |||
|
41 | } No newline at end of file |
@@ -1,6 +1,6 | |||||
1 | <Project Sdk="Microsoft.NET.Sdk"> |
|
1 | <Project Sdk="Microsoft.NET.Sdk"> | |
2 | <PropertyGroup Condition="'$(OSTYPE)'=='linux'"> |
|
2 | <PropertyGroup Condition="'$(OSTYPE)'=='linux'"> | |
3 | <TargetFramework>netcoreapp2.0</TargetFramework> |
|
3 | <TargetFrameworks>netcoreapp2.0;;net46</TargetFrameworks> | |
4 | <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.6-api/</FrameworkPathOverride> |
|
4 | <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.6-api/</FrameworkPathOverride> | |
5 | </PropertyGroup> |
|
5 | </PropertyGroup> | |
6 |
|
6 |
@@ -24,9 +24,16 namespace Implab.Playground { | |||||
24 | public class Program { |
|
24 | public class Program { | |
25 |
|
25 | |||
26 | static void Main(string[] args) { |
|
26 | static void Main(string[] args) { | |
|
27 | Trace<Foo>.Log("First!"); | |||
|
28 | Log("+1!"); | |||
27 |
|
29 | |||
28 |
using(TraceRegistry.Global.Subscribe( |
|
30 | using(TraceRegistry.Global.Subscribe(x => { | |
|
31 | var ch = x as TraceSourceChannel; | |||
|
32 | if (ch == null) | |||
|
33 | return; | |||
|
34 | ||||
29 | Console.WriteLine($"{ch.Id}: {ch.Source.Name}"); |
|
35 | Console.WriteLine($"{ch.Id}: {ch.Source.Name}"); | |
|
36 | ||||
30 | }, true)) { |
|
37 | }, true)) { | |
31 | Trace<Foo>.Log("Hi!"); |
|
38 | Trace<Foo>.Log("Hi!"); | |
32 | Log("Respect!"); |
|
39 | Log("Respect!"); |
@@ -12,16 +12,23 using System.Threading.Tasks; | |||||
12 | namespace Implab.Diagnostics { |
|
12 | namespace Implab.Diagnostics { | |
13 | /// <summary> |
|
13 | /// <summary> | |
14 | /// Static class which creates an individual <see cref="TraceSource"/> for |
|
14 | /// Static class which creates an individual <see cref="TraceSource"/> for | |
15 |
/// the type specified in the parameter <typeparamref name="T"/> |
|
15 | /// the type specified in the parameter <typeparamref name="T"/> and uses | |
|
16 | /// it to perform logging operations. | |||
16 | /// </summary> |
|
17 | /// </summary> | |
17 | /// <typeparam name="T">The type for which tracing is demanded.</typeparam> |
|
18 | /// <typeparam name="T">The type for which tracing is demanded.</typeparam> | |
18 | public static class Trace<T> { |
|
19 | public static class Trace<T> { | |
19 |
|
20 | |||
20 | readonly static Lazy<TraceSource> _trace = new Lazy<TraceSource>(() => TraceSourceChannel<T>.Default.Source); |
|
21 | readonly static Lazy<TraceSource> _trace = new Lazy<TraceSource>(() => TraceSourceChannel<T>.Default.Source); | |
21 |
|
22 | |||
|
23 | /// <summary> | |||
|
24 | /// The <see cref="TraceSource"/> associated with the current class. | |||
|
25 | /// TraceSource is created using <see cref="TraceSourceChannel{T}"/>. | |||
|
26 | /// </summary> | |||
22 | public static TraceSource TraceSource { get { return _trace.Value; } } |
|
27 | public static TraceSource TraceSource { get { return _trace.Value; } } | |
23 |
|
28 | |||
24 | #if NETFX_TRACE_BUG |
|
29 | #if NETFX_TRACE_BUG | |
|
30 | // AsyncLocal will store value inside the current execution context | |||
|
31 | // and will force it to be copied... not a very effective solution. | |||
25 | readonly static AsyncLocal<object> m_currentOperation = new AsyncLocal<object>(); |
|
32 | readonly static AsyncLocal<object> m_currentOperation = new AsyncLocal<object>(); | |
26 | #endif |
|
33 | #endif | |
27 |
|
34 |
@@ -23,7 +23,7 namespace Implab.Diagnostics { | |||||
23 | public static TraceSourceChannel Default { get { return _traceSource.Value; } } |
|
23 | public static TraceSourceChannel Default { get { return _traceSource.Value; } } | |
24 |
|
24 | |||
25 | static TraceSourceChannel CreateChannel() { |
|
25 | static TraceSourceChannel CreateChannel() { | |
26 | var channel = new TraceSourceChannel(typeof(T), typeof(T).Name); |
|
26 | var channel = new TraceSourceChannel(typeof(T), typeof(T).FullName); | |
27 |
|
27 | |||
28 | TraceRegistry.Global.Register(channel); |
|
28 | TraceRegistry.Global.Register(channel); | |
29 |
|
29 |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 3
ok, latest stable version should be in default
You need to be logged in to leave comments.
Login now