Skip to content

Commit 0431b7e

Browse files
Sergey KanzhelevSergey Kanzhelev
authored andcommitted
working app
1 parent 7a907d0 commit 0431b7e

File tree

8 files changed

+109
-24
lines changed

8 files changed

+109
-24
lines changed

SimpleConsoleApp.sln

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2013
4-
VisualStudioVersion = 12.0.31101.0
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleConsoleApp", "SimpleConsoleApp\SimpleConsoleApp.csproj", "{17615840-CE31-4591-BC12-4D0B342949A9}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
11-
Debug|x64 = Debug|x64
1211
Release|Any CPU = Release|Any CPU
13-
Release|x64 = Release|x64
1412
EndGlobalSection
1513
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1614
{17615840-CE31-4591-BC12-4D0B342949A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1715
{17615840-CE31-4591-BC12-4D0B342949A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
18-
{17615840-CE31-4591-BC12-4D0B342949A9}.Debug|x64.ActiveCfg = Debug|x64
19-
{17615840-CE31-4591-BC12-4D0B342949A9}.Debug|x64.Build.0 = Debug|x64
2016
{17615840-CE31-4591-BC12-4D0B342949A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
2117
{17615840-CE31-4591-BC12-4D0B342949A9}.Release|Any CPU.Build.0 = Release|Any CPU
22-
{17615840-CE31-4591-BC12-4D0B342949A9}.Release|x64.ActiveCfg = Release|x64
23-
{17615840-CE31-4591-BC12-4D0B342949A9}.Release|x64.Build.0 = Release|x64
2418
EndGlobalSection
2519
GlobalSection(SolutionProperties) = preSolution
2620
HideSolutionNode = FALSE

SimpleConsoleApp/App.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
55
</startup>
6-
</configuration>
6+
</configuration>

SimpleConsoleApp/Program.cs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
using System;
1+
using Microsoft.Diagnostics.Instrumentation.Extensions.Intercept;
2+
using System;
23
using System.Collections.Generic;
4+
using System.Diagnostics;
35
using System.Linq;
46
using System.Text;
7+
using System.Threading;
58
using System.Threading.Tasks;
69

710
namespace SimpleConsoleApp
@@ -10,7 +13,58 @@ class Program
1013
{
1114
static void Main(string[] args)
1215
{
16+
if (!Decorator.IsHostEnabled())
17+
{
18+
Console.WriteLine("Please run this application using Startup.cmd script.");
19+
return;
20+
}
1321

22+
Console.WriteLine("Agent version: " + Decorator.GetAgentVersion());
23+
24+
Decorator.InitializeExtension();
25+
Functions.Decorate("System", "System.dll", "System.Net.Mail.SmtpClient.Send", OnBegin, OnEnd, OnException, false);
26+
27+
// this wait is required in case you've already called "SmtpClient.Send" method before. Just give some time to requiest re-JIT
28+
Thread.Sleep(1000);
29+
30+
Execute();
31+
32+
Console.ReadLine();
33+
}
34+
35+
public static void Execute()
36+
{
37+
try
38+
{
39+
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
40+
client.Send(null);
41+
}
42+
catch (Exception)
43+
{
44+
//this is expected to throw
45+
}
46+
}
47+
48+
public static object OnBegin(object thisObj, object arg1)
49+
{
50+
Console.WriteLine("Begin callback");
51+
Console.WriteLine("Callstack: " + new StackTrace().ToString());
52+
53+
return null;
54+
}
55+
56+
public static object OnEnd(object context, object returnValue, object thisObj, object arg1)
57+
{
58+
Console.WriteLine("End callback");
59+
Console.WriteLine("Callstack: " + new StackTrace().ToString());
60+
61+
return returnValue;
62+
}
63+
64+
public static void OnException(object context, object exception, object thisObj, object arg1)
65+
{
66+
Console.WriteLine("Exception callback");
67+
Console.WriteLine("Callstack: " + new StackTrace().ToString());
1468
}
1569
}
1670
}

SimpleConsoleApp/SimpleConsoleApp.csproj

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>SimpleConsoleApp</RootNamespace>
1111
<AssemblyName>SimpleConsoleApp</AssemblyName>
12-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
1415
</PropertyGroup>
1516
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1617
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -52,6 +53,10 @@
5253
<Prefer32Bit>true</Prefer32Bit>
5354
</PropertyGroup>
5455
<ItemGroup>
56+
<Reference Include="Microsoft.AI.Agent.Intercept, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
57+
<HintPath>..\packages\Microsoft.ApplicationInsights.Agent.Intercept.2.0.5\lib\net45\Microsoft.AI.Agent.Intercept.dll</HintPath>
58+
<Private>True</Private>
59+
</Reference>
5560
<Reference Include="System" />
5661
<Reference Include="System.Core" />
5762
<Reference Include="System.Xml.Linq" />
@@ -66,11 +71,14 @@
6671
</ItemGroup>
6772
<ItemGroup>
6873
<None Include="App.config" />
69-
<None Include="packages.config" />
74+
<None Include="nuget.config" />
75+
<None Include="packages.config">
76+
<SubType>Designer</SubType>
77+
</None>
7078
<None Include="RTIA\x64\Microsoft.InstrumentationEngine.Extensions.config">
7179
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7280
</None>
73-
<None Include="RTIA\x64\start.cmd">
81+
<None Include="RTIA\x86\Microsoft.InstrumentationEngine.Extensions.config">
7482
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7583
</None>
7684
<None Include="Startup.cmd" />
@@ -82,16 +90,22 @@
8290
<Content Include="RTIA\x64\Microsoft.ApplicationInsights.ExtensionsHost_x64.dll">
8391
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
8492
</Content>
85-
<Content Include="RTIA\x64\Microsoft.ApplicationInsights.StartupAction_x64.dll">
86-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
87-
</Content>
8893
<Content Include="RTIA\x64\Microsoft.Diagnostics.Instrumentation.Extensions.Base.dll">
8994
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9095
</Content>
9196
<Content Include="RTIA\x64\MicrosoftInstrumentationEngine_x64.dll">
9297
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9398
</Content>
94-
<Content Include="RTIA\x64\vsassert.dll">
99+
<Content Include="RTIA\x86\Microsoft.ApplicationInsights.Extensions.Base_x86.dll">
100+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
101+
</Content>
102+
<Content Include="RTIA\x86\Microsoft.ApplicationInsights.ExtensionsHost_x86.dll">
103+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
104+
</Content>
105+
<Content Include="RTIA\x86\Microsoft.Diagnostics.Instrumentation.Extensions.Base.dll">
106+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
107+
</Content>
108+
<Content Include="RTIA\x86\MicrosoftInstrumentationEngine_x86.dll">
95109
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
96110
</Content>
97111
</ItemGroup>

SimpleConsoleApp/Startup.cmd

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
SET COR_ENABLE_PROFILING=1
22
SET COR_PROFILER={324F817A-7420-4E6D-B3C1-143FBED6D855}
3-
SET COR_PROFILER_PATH=RTIA\x64\MicrosoftInstrumentationEngine_x64.dll
4-
SET MicrosoftInstrumentationEngine_HostPath=%cd%\RTIA\x64\Microsoft.ApplicationInsights.ExtensionsHost_x64.dll
3+
SET "COR_PROFILER_PATH_64=%~dp0\RTIA\x64\MicrosoftInstrumentationEngine_x64.dll"
4+
SET "COR_PROFILER_PATH_32=%~dp0\RTIA\x86\MicrosoftInstrumentationEngine_x86.dll"
5+
SET "MicrosoftInstrumentationEngine_HostPath_64=%~dp0\RTIA\x64\Microsoft.ApplicationInsights.ExtensionsHost_x64.dll"
6+
SET "MicrosoftInstrumentationEngine_HostPath_32=%~dp0\RTIA\x86\Microsoft.ApplicationInsights.ExtensionsHost_x86.dll"
57
SET MicrosoftInstrumentationEngine_Host={CA487940-57D2-10BF-11B2-A3AD5A13CBC0}
68
SET MicrosoftInstrumentationEngine_MessageboxAtAttach=1
79
SET MicrosoftInstrumentationEngine_FileLog="Errors|Dumps"
810

9-
bin\x64\Debug\SimpleConsoleApp.exe
11+
"%~dp0\bin\Debug\SimpleConsoleApp.exe

SimpleConsoleApp/nuget.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<config>
4+
<add key="repositoryPath" value=".\packages" />
5+
</config>
6+
<packageSources>
7+
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
8+
<add key="application insights myget" value="https://myget.org/f/applicationinsights/" />
9+
</packageSources>
10+
</configuration>

SimpleConsoleApp/packages.config

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Diagnostics.RuntimeInstrumentationAgent.Extensions.StartupAction_x64" version="0.13.0-build31099" targetFramework="net45" />
4-
<package id="Microsoft.Diagnostics.RuntimeInstrumentationAgent_x64" version="0.13.0-build31044" targetFramework="net45" />
3+
<package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.0.5" targetFramework="net46" />
4+
<package id="Microsoft.ApplicationInsights.Agent_x64" version="2.0.5" targetFramework="net46" />
5+
<package id="Microsoft.ApplicationInsights.Agent_x86" version="2.0.5" targetFramework="net46" />
56
</packages>

nuget.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<config>
4+
<add key="repositoryPath" value=".\packages" />
5+
</config>
6+
<packageSources>
7+
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
8+
<add key="application insights myget" value="https://myget.org/f/applicationinsights/" />
9+
</packageSources>
10+
</configuration>

0 commit comments

Comments
 (0)