7
7
using System . Runtime . InteropServices ;
8
8
using System . Text ;
9
9
using System . Threading ;
10
- using Exceptionless . Extras . Utility ;
11
10
using Exceptionless . Logging ;
12
11
using Exceptionless . Models . Data ;
13
12
using Microsoft . VisualBasic . Devices ;
@@ -35,32 +34,31 @@ public EnvironmentInfo GetEnvironmentInfo() {
35
34
}
36
35
37
36
try {
38
- if ( computerInfo != null )
37
+ if ( computerInfo != null ) {
39
38
info . OSName = computerInfo . OSFullName ;
40
- if ( computerInfo != null )
41
39
info . OSVersion = computerInfo . OSVersion ;
40
+ }
42
41
} catch ( Exception ex ) {
43
42
_log . FormattedInfo ( typeof ( EnvironmentInfoCollector ) , "Unable to get operating system version. Error message: {0}" , ex . Message ) ;
44
43
}
45
44
46
45
try {
47
- if ( EnvironmentHelper . IsUnix )
46
+ if ( IsUnix )
48
47
{
49
48
if ( PerformanceCounterCategory . Exists ( "Mono Memory" ) )
50
49
{
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 ) ;
50
+ var totalPhysicalMemory = new PerformanceCounter ( "Mono Memory" , "Total Physical Memory" ) ;
51
+ var availablePhysicalMemory = new PerformanceCounter ( "Mono Memory" , "Available Physical Memory" ) ; //mono 4.0+
52
+ info . TotalPhysicalMemory = Convert . ToInt64 ( totalPhysicalMemory . RawValue ) ;
53
+ info . AvailablePhysicalMemory = Convert . ToInt64 ( availablePhysicalMemory . RawValue ) ;
56
54
}
57
55
}
58
56
else
59
57
{
60
- if ( computerInfo != null )
58
+ if ( computerInfo != null ) {
61
59
info . TotalPhysicalMemory = Convert . ToInt64 ( computerInfo . TotalPhysicalMemory ) ;
62
- if ( computerInfo != null )
63
60
info . AvailablePhysicalMemory = Convert . ToInt64 ( computerInfo . AvailablePhysicalMemory ) ;
61
+ }
64
62
}
65
63
} catch ( Exception ex ) {
66
64
_log . FormattedInfo ( typeof ( EnvironmentInfoCollector ) , "Unable to get physical memory. Error message: {0}" , ex . Message ) ;
@@ -100,10 +98,10 @@ public EnvironmentInfo GetEnvironmentInfo() {
100
98
}
101
99
102
100
try {
103
- if ( EnvironmentHelper . IsUnix )
101
+ if ( IsUnix )
104
102
{
105
103
var currentProcess = Process . GetCurrentProcess ( ) ;
106
- info . ProcessId = currentProcess . Id . ToString ( ) ;
104
+ info . ProcessId = currentProcess . Id . ToString ( NumberFormatInfo . InvariantInfo ) ;
107
105
}
108
106
else
109
107
{
@@ -114,7 +112,7 @@ public EnvironmentInfo GetEnvironmentInfo() {
114
112
}
115
113
116
114
try {
117
- if ( EnvironmentHelper . IsUnix )
115
+ if ( IsUnix )
118
116
{
119
117
var currentProcess = Process . GetCurrentProcess ( ) ;
120
118
info . ProcessName = currentProcess . ProcessName ;
@@ -128,9 +126,9 @@ public EnvironmentInfo GetEnvironmentInfo() {
128
126
}
129
127
130
128
try {
131
- if ( EnvironmentHelper . IsUnix )
129
+ if ( IsUnix )
132
130
{
133
- info . ThreadId = System . Threading . Thread . CurrentThread . ManagedThreadId . ToString ( ) ;
131
+ info . ThreadId = System . Threading . Thread . CurrentThread . ManagedThreadId . ToString ( NumberFormatInfo . InvariantInfo ) ;
134
132
}
135
133
else
136
134
{
@@ -184,6 +182,19 @@ private static bool Is64BitOperatingSystem() {
184
182
185
183
return ( ( methodExist && KernelNativeMethods . IsWow64Process ( KernelNativeMethods . GetCurrentProcess ( ) , out is64 ) ) && is64 ) ;
186
184
}
185
+
186
+ /// <summary>
187
+ /// Determine current os platform.
188
+ /// </summary>
189
+ /// <exception cref="InvalidOperationException" accessor="get"></exception>
190
+ private static bool IsUnix
191
+ {
192
+ get
193
+ {
194
+ int p = ( int ) Environment . OSVersion . Platform ;
195
+ return ( p == 4 ) || ( p == 6 ) || ( p == 128 ) ;
196
+ }
197
+ }
187
198
}
188
199
189
200
internal static class KernelNativeMethods {
0 commit comments