Skip to content

Commit

Permalink
Move StartupHooks over to netstandard2.0 (#2239)
Browse files Browse the repository at this point in the history
* Move StartupHooks over to netstandard2.0

* dotnet format
  • Loading branch information
Mpdreamz authored Dec 12, 2023
1 parent 506e673 commit fd4ba0c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 35 deletions.
6 changes: 3 additions & 3 deletions build/scripts/Build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ module Build =
agentDir.Create()

// copy startup hook to root of agent directory
!! (Paths.BuildOutput "ElasticApmAgentStartupHook/netcoreapp2.2")
!! (Paths.BuildOutput "ElasticApmAgentStartupHook/netstandard2.0")
|> Seq.filter Path.isDirectory
|> Seq.map DirectoryInfo
|> Seq.iter (copyDllsAndPdbs agentDir)
Expand All @@ -231,14 +231,14 @@ module Build =
|> Seq.iter (copyDllsAndPdbs (agentDir.CreateSubdirectory(sprintf "%i.0.0" getCurrentApmDiagnosticSourceVersion.Major)))

// assemblies compiled against older version of System.Diagnostics.DiagnosticSource
!! (Paths.BuildOutput (sprintf "Elastic.Apm.StartupHook.Loader_%i.0.0/netcoreapp2.2" oldDiagnosticSourceVersion.Major))
!! (Paths.BuildOutput (sprintf "Elastic.Apm.StartupHook.Loader_%i.0.0/netstandard2.0" oldDiagnosticSourceVersion.Major))
++ (Paths.BuildOutput (sprintf "Elastic.Apm_%i.0.0/netstandard2.0" oldDiagnosticSourceVersion.Major))
|> Seq.filter Path.isDirectory
|> Seq.map DirectoryInfo
|> Seq.iter (copyDllsAndPdbs (agentDir.CreateSubdirectory(sprintf "%i.0.0" oldDiagnosticSourceVersion.Major)))

// assemblies compiled against 6.0 version of System.Diagnostics.DiagnosticSource
!! (Paths.BuildOutput (sprintf "Elastic.Apm.StartupHook.Loader_%i.0.0/netcoreapp2.2" oldDiagnosticSourceVersion.Major)) //using old version here, because it the netcoreapp2.2 app can't build with diagnosticsource6
!! (Paths.BuildOutput (sprintf "Elastic.Apm.StartupHook.Loader_%i.0.0/netstandard2.0" oldDiagnosticSourceVersion.Major)) //using old version here, because it the netcoreapp2.2 app can't build with diagnosticsource6
++ (Paths.BuildOutput (sprintf "Elastic.Apm_%i.0.0/net6.0" diagnosticSourceVersion6.Major))
|> Seq.filter Path.isDirectory
|> Seq.map DirectoryInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- TODO make this netstandard 2.0 and ref System.Runtime.Loader -->
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Elastic.Apm\Elastic.Apm.csproj" />
<ProjectReference Include="..\..\integrations\Elastic.Apm.AspNetCore\Elastic.Apm.AspNetCore.csproj" />
<ProjectReference Include="..\..\instrumentations\Elastic.Apm.Elasticsearch\Elastic.Apm.Elasticsearch.csproj" />
<ProjectReference Include="..\..\instrumentations\Elastic.Apm.EntityFrameworkCore\Elastic.Apm.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\instrumentations\Elastic.Apm.GrpcClient\Elastic.Apm.GrpcClient.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Elastic.Apm\Elastic.Apm.csproj"/>
<ProjectReference Include="..\..\integrations\Elastic.Apm.AspNetCore\Elastic.Apm.AspNetCore.csproj"/>
<ProjectReference Include="..\..\instrumentations\Elastic.Apm.Elasticsearch\Elastic.Apm.Elasticsearch.csproj"/>
<ProjectReference Include="..\..\instrumentations\Elastic.Apm.EntityFrameworkCore\Elastic.Apm.EntityFrameworkCore.csproj"/>
<ProjectReference Include="..\..\instrumentations\Elastic.Apm.GrpcClient\Elastic.Apm.GrpcClient.csproj"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.Loader" Version="4.3.0"/>
</ItemGroup>

<ItemGroup>
<Compile Include="..\ElasticApmAgentStartupHook\StartupHookLogger.cs">
<Link>StartupHookLogger.cs</Link>
</Compile>
</ItemGroup>

<ItemGroup>
<Compile Include="..\ElasticApmAgentStartupHook\StartupHookLogger.cs">
<Link>StartupHookLogger.cs</Link>
</Compile>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- TODO make this netstandard 2.0 and ref System.Runtime.Loader -->
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>ElasticApmAgentStartupHook</AssemblyName>
<IsPackable>false</IsPackable>
<RootNamespace>ElasticApmStartupHook</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup>
</Project>
24 changes: 12 additions & 12 deletions src/startuphook/ElasticApmAgentStartupHook/StartupHookLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ public static StartupHookLogger Create()

public void WriteLine(string message)
{
if (_enabled)
if (!_enabled)
return;

try
{
var log = $"[{DateTime.Now:u}] {message}";
Console.Out.WriteLine(log);
Console.Out.Flush();
File.AppendAllLines(_logPath, new[] { log });
}
catch
{
try
{
var log = $"[{DateTime.Now:u}] {message}";
Console.Out.WriteLine(log);
Console.Out.Flush();
File.AppendAllLines(_logPath, new[] { log });
}
catch
{
// if we can't log a log message, there's not much that can be done, so ignore
}
// if we can't log a log message, there's not much that can be done, so ignore
}
}
}
Expand Down

0 comments on commit fd4ba0c

Please sign in to comment.