Skip to content

Commit e8b9716

Browse files
Update System.Diagnostics.DiagnosticSource (#5140) (#5153)
* Update System.Diagnostics.DiagnosticSource - Update to use the latest 5.0.0 version which supports all targets. * Implement IDisposable Co-authored-by: Steve Gordon <[email protected]>
1 parent 1f8fc5f commit e8b9716

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/Elasticsearch.Net/Diagnostics/Diagnostic.cs

+17-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ public Diagnostic(string operationName, DiagnosticSource source, TState state)
1818
EndState = state;
1919
}
2020

21-
internal class Diagnostic<TState, TStateEnd> : Activity, IDisposable
21+
internal class Diagnostic<TState, TStateEnd> : Activity
2222
{
23-
public static Diagnostic<TState, TStateEnd> Default { get; } = new Diagnostic<TState, TStateEnd>();
23+
public static Diagnostic<TState, TStateEnd> Default { get; } = new();
2424

2525
private readonly DiagnosticSource _source;
2626
private TStateEnd _endState;
2727
private readonly bool _default;
28+
private bool _disposed;
2829

2930
private Diagnostic() : base("__NOOP__") => _default = true;
3031

@@ -44,9 +45,20 @@ internal set
4445
_endState = value;
4546
}
4647
}
48+
49+
protected override void Dispose(bool disposing)
50+
{
51+
if (_disposed) return;
4752

53+
if (disposing)
54+
{
55+
//_source can be null if Default instance
56+
_source?.StopActivity(SetEndTime(DateTime.UtcNow), EndState);
57+
}
4858

49-
//_source can be null if Default instance
50-
public void Dispose() => _source?.StopActivity(SetEndTime(DateTime.UtcNow), EndState);
59+
_disposed = true;
60+
61+
base.Dispose(disposing);
62+
}
5163
}
52-
}
64+
}

src/Elasticsearch.Net/Elasticsearch.Net.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
</PropertyGroup>
2222
<ItemGroup>
2323
<PackageReference Include="Microsoft.CSharp" Version="4.6.0" />
24-
<PackageReference Include="System.Buffers" Version="4.5.0" />
25-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
24+
<PackageReference Include="System.Buffers" Version="4.5.1" />
25+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.0" />
2626

2727
<PackageReference Condition="'$(TargetFramework)' == 'netstandard2.0'" Include="System.Reflection.Emit" Version="4.3.0" />
2828
<PackageReference Condition="'$(TargetFramework)' == 'netstandard2.0'" Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />

tests/Tests.ScratchPad/Tests.ScratchPad.csproj

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
<Optimize>true</Optimize>
66
<DebugSymbols>true</DebugSymbols>
77
</PropertyGroup>
8+
89
<ItemGroup>
9-
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
1010
<ProjectReference Include="..\Tests.Core\Tests.Core.csproj" />
11-
<PackageReference Include="BenchMarkDotNet" Version="0.11.5" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.0" />
15+
<PackageReference Include="BenchMarkDotNet" Version="0.12.1" />
1216
</ItemGroup>
1317
</Project>

0 commit comments

Comments
 (0)