|
7 | 7 | using System.Runtime.InteropServices;
|
8 | 8 | using System.Text;
|
9 | 9 | using System.Threading;
|
| 10 | +using Exceptionless.Extras.Utility; |
10 | 11 | using Exceptionless.Logging;
|
11 | 12 | using Exceptionless.Models.Data;
|
12 | 13 | using Microsoft.VisualBasic.Devices;
|
@@ -43,10 +44,24 @@ public EnvironmentInfo GetEnvironmentInfo() {
|
43 | 44 | }
|
44 | 45 |
|
45 | 46 | try {
|
46 |
| - if (computerInfo != null) |
47 |
| - info.TotalPhysicalMemory = Convert.ToInt64(computerInfo.TotalPhysicalMemory); |
48 |
| - if (computerInfo != null) |
49 |
| - info.AvailablePhysicalMemory = Convert.ToInt64(computerInfo.AvailablePhysicalMemory); |
| 47 | + if (EnvironmentHelper.IsUnix) |
| 48 | + { |
| 49 | + if (PerformanceCounterCategory.Exists("Mono Memory")) |
| 50 | + { |
| 51 | + //https://github.com/mono/mono/blob/f0834d5407f492a2a21e2f62f8f8c418d64ba6fa/mono/metadata/mono-perfcounters-def.h |
| 52 | + var performanceCounterTotalPhysicalMemory = new PerformanceCounter("Mono Memory", "Total Physical Memory"); |
| 53 | + var performanceCounterAvailablePhysicalMemory = new PerformanceCounter("Mono Memory", "Available Physical Memory"); //mono 4.0+ |
| 54 | + info.TotalPhysicalMemory = Convert.ToInt64(performanceCounterTotalPhysicalMemory.RawValue); |
| 55 | + info.AvailablePhysicalMemory = Convert.ToInt64(performanceCounterAvailablePhysicalMemory.RawValue); |
| 56 | + } |
| 57 | + } |
| 58 | + else |
| 59 | + { |
| 60 | + if (computerInfo != null) |
| 61 | + info.TotalPhysicalMemory = Convert.ToInt64(computerInfo.TotalPhysicalMemory); |
| 62 | + if (computerInfo != null) |
| 63 | + info.AvailablePhysicalMemory = Convert.ToInt64(computerInfo.AvailablePhysicalMemory); |
| 64 | + } |
50 | 65 | } catch (Exception ex) {
|
51 | 66 | _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get physical memory. Error message: {0}", ex.Message);
|
52 | 67 | }
|
@@ -85,19 +100,42 @@ public EnvironmentInfo GetEnvironmentInfo() {
|
85 | 100 | }
|
86 | 101 |
|
87 | 102 | try {
|
88 |
| - info.ProcessId = KernelNativeMethods.GetCurrentProcessId().ToString(NumberFormatInfo.InvariantInfo); |
| 103 | + if (EnvironmentHelper.IsUnix) |
| 104 | + { |
| 105 | + var currentProcess = Process.GetCurrentProcess(); |
| 106 | + info.ProcessId = currentProcess.Id.ToString(); |
| 107 | + } |
| 108 | + else |
| 109 | + { |
| 110 | + info.ProcessId = KernelNativeMethods.GetCurrentProcessId().ToString(NumberFormatInfo.InvariantInfo); |
| 111 | + } |
89 | 112 | } catch (Exception ex) {
|
90 | 113 | _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get process id. Error message: {0}", ex.Message);
|
91 | 114 | }
|
92 | 115 |
|
93 | 116 | try {
|
94 |
| - info.ProcessName = GetProcessName(); |
| 117 | + if (EnvironmentHelper.IsUnix) |
| 118 | + { |
| 119 | + var currentProcess = Process.GetCurrentProcess(); |
| 120 | + info.ProcessName = currentProcess.ProcessName; |
| 121 | + } |
| 122 | + else |
| 123 | + { |
| 124 | + info.ProcessName = GetProcessName(); |
| 125 | + } |
95 | 126 | } catch (Exception ex) {
|
96 | 127 | _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get process name. Error message: {0}", ex.Message);
|
97 | 128 | }
|
98 | 129 |
|
99 | 130 | try {
|
100 |
| - info.ThreadId = KernelNativeMethods.GetCurrentThreadId().ToString(NumberFormatInfo.InvariantInfo); |
| 131 | + if (EnvironmentHelper.IsUnix) |
| 132 | + { |
| 133 | + info.ThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString(); |
| 134 | + } |
| 135 | + else |
| 136 | + { |
| 137 | + info.ThreadId = KernelNativeMethods.GetCurrentThreadId().ToString(NumberFormatInfo.InvariantInfo); |
| 138 | + } |
101 | 139 | } catch (Exception ex) {
|
102 | 140 | _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get thread id. Error message: {0}", ex.Message);
|
103 | 141 | }
|
|
0 commit comments