Skip to content

Commit 57df252

Browse files
committed
Implemented rtm runtime info
@ejsmith now they just give you OS Description that could be anything.. In this case Microsoft Windows 10.0.586.. I convert that to OSName -> Microsoft Windows 10 (with minor if greater than 0) and os version properly.. Runtime Version is parsed from Framework Description (mine returns .NET Core 4.0.0).
1 parent d39605d commit 57df252

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

src/Exceptionless.Signed/project.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"System.Resources.ResourceManager": "4.0.1",
7272
"System.Runtime": "4.1.0",
7373
"System.Runtime.Extensions": "4.1.0",
74+
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
7475
"System.Runtime.Numerics": "4.0.1",
7576
"System.Runtime.Serialization.Primitives": "4.1.1",
7677
"System.Text.Encoding": "4.0.11",
@@ -121,6 +122,7 @@
121122
"System.Resources.ResourceManager": "4.0.1",
122123
"System.Runtime": "4.1.0",
123124
"System.Runtime.Extensions": "4.1.0",
125+
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
124126
"System.Runtime.Numerics": "4.0.1",
125127
"System.Runtime.Serialization.Primitives": "4.1.1",
126128
"System.Security.AccessControl": "4.0.0",
@@ -176,6 +178,7 @@
176178
"System.Resources.ResourceManager": "4.0.1",
177179
"System.Runtime": "4.1.0",
178180
"System.Runtime.Extensions": "4.1.0",
181+
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
179182
"System.Runtime.Numerics": "4.0.1",
180183
"System.Runtime.Serialization.Primitives": "4.1.1",
181184
"System.Security.AccessControl": "4.0.0",
@@ -231,6 +234,7 @@
231234
"System.Resources.ResourceManager": "4.0.1",
232235
"System.Runtime": "4.1.0",
233236
"System.Runtime.Extensions": "4.1.0",
237+
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
234238
"System.Runtime.Numerics": "4.0.1",
235239
"System.Runtime.Serialization.Primitives": "4.1.1",
236240
"System.Security.AccessControl": "4.0.0",

src/Exceptionless/Services/DefaultEnvironmentInfoCollector.cs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ private bool IsMonoRuntime {
146146
#endif
147147

148148
private void PopulateRuntimeInfo(EnvironmentInfo info) {
149+
#if NETSTANDARD
150+
info.OSName = GetOSName(RuntimeInformation.OSDescription);
151+
info.OSVersion = GetVersion(RuntimeInformation.OSDescription)?.ToString();
152+
info.Architecture = RuntimeInformation.OSArchitecture.ToString();
153+
info.RuntimeVersion = GetVersion(RuntimeInformation.FrameworkDescription)?.ToString();
154+
info.Data["FrameworkDescription"] = RuntimeInformation.FrameworkDescription;
155+
info.Data["ProcessArchitecture"] = RuntimeInformation.ProcessArchitecture;
156+
#endif
157+
149158
try {
150159
#if NET45 || NETSTANDARD1_5
151160
info.MachineName = Environment.MachineName;
@@ -186,12 +195,6 @@ private void PopulateRuntimeInfo(EnvironmentInfo info) {
186195
info.Data["ApplicationBasePath"] = computerInfo.Application.ApplicationBasePath;
187196
info.Data["ApplicationName"] = computerInfo.Application.ApplicationName;
188197
info.Data["RuntimeFramework"] = computerInfo.Application.RuntimeFramework.FullName;
189-
190-
info.OSName = computerInfo.Runtime.OperatingSystem;
191-
info.OSVersion = computerInfo.Runtime.OperatingSystemVersion;
192-
info.Architecture = computerInfo.Runtime.RuntimeArchitecture;
193-
info.RuntimeVersion = computerInfo.Runtime.RuntimeVersion;
194-
info.Data["RuntimeType"] = computerInfo.Runtime.RuntimeType; // Mono, CLR, CoreCLR
195198
#elif NET45
196199
info.OSName = computerInfo.OSFullName;
197200
info.OSVersion = computerInfo.OSVersion;
@@ -202,8 +205,35 @@ private void PopulateRuntimeInfo(EnvironmentInfo info) {
202205
_log.FormattedInfo(typeof(DefaultEnvironmentInfoCollector), "Unable to get populate runtime info. Error message: {0}", ex.Message);
203206
}
204207
#endif
208+
}
209+
210+
#if NETSTANDARD
211+
private string GetOSName(string osDescription) {
212+
if (String.IsNullOrEmpty(osDescription))
213+
return null;
214+
215+
var version = GetVersion(osDescription);
216+
if (version != null)
217+
return osDescription.Replace(version.ToString(), version.ToString(version.Minor == 0 ? 1 : 2));
218+
219+
return osDescription;
220+
}
221+
222+
private Version GetVersion(string description) {
223+
if (String.IsNullOrEmpty(description))
224+
return null;
225+
226+
var parts = description.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
227+
if (parts.Length > 0) {
228+
Version version;
229+
if (Version.TryParse(parts[parts.Length - 1], out version))
230+
return version;
205231
}
206232

233+
return null;
234+
}
235+
#endif
236+
207237
#if NET45
208238
private bool Is64BitOperatingSystem() {
209239
if (IntPtr.Size == 8) // 64-bit programs run only on Win64
@@ -223,7 +253,7 @@ private bool Is64BitOperatingSystem() {
223253
}
224254

225255
private static class KernelNativeMethods {
226-
#region Kernel32
256+
#region Kernel32
227257

228258
[DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
229259
public static extern IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string procName);
@@ -248,7 +278,7 @@ private static class KernelNativeMethods {
248278
[DllImport("kernel32.dll")]
249279
public static extern int GetCurrentThreadId();
250280

251-
#endregion
281+
#endregion
252282

253283
public static bool MethodExists(string moduleName, string methodName) {
254284
IntPtr moduleHandle = GetModuleHandle(moduleName);

src/Exceptionless/project.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"System.Resources.ResourceManager": "4.0.1",
6363
"System.Runtime": "4.1.0",
6464
"System.Runtime.Extensions": "4.1.0",
65+
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
6566
"System.Runtime.Numerics": "4.0.1",
6667
"System.Runtime.Serialization.Primitives": "4.1.1",
6768
"System.Text.Encoding": "4.0.11",
@@ -112,6 +113,7 @@
112113
"System.Resources.ResourceManager": "4.0.1",
113114
"System.Runtime": "4.1.0",
114115
"System.Runtime.Extensions": "4.1.0",
116+
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
115117
"System.Runtime.Numerics": "4.0.1",
116118
"System.Runtime.Serialization.Primitives": "4.1.1",
117119
"System.Security.AccessControl": "4.0.0",
@@ -167,6 +169,7 @@
167169
"System.Resources.ResourceManager": "4.0.1",
168170
"System.Runtime": "4.1.0",
169171
"System.Runtime.Extensions": "4.1.0",
172+
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
170173
"System.Runtime.Numerics": "4.0.1",
171174
"System.Runtime.Serialization.Primitives": "4.1.1",
172175
"System.Security.AccessControl": "4.0.0",
@@ -222,6 +225,7 @@
222225
"System.Resources.ResourceManager": "4.0.1",
223226
"System.Runtime": "4.1.0",
224227
"System.Runtime.Extensions": "4.1.0",
228+
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
225229
"System.Runtime.Numerics": "4.0.1",
226230
"System.Runtime.Serialization.Primitives": "4.1.1",
227231
"System.Security.AccessControl": "4.0.0",

0 commit comments

Comments
 (0)