Table of Contents

Class SystemInfo

Namespace
log4net.Util
Assembly
log4net.dll

Utility class for system specific information.

public sealed class SystemInfo
Inheritance
SystemInfo
Inherited Members

Remarks

Utility class of static methods for system specific information.

Fields

EmptyTypes

Gets an empty array of types.

public static readonly Type[] EmptyTypes

Field Value

Type[]

Remarks

The Type.EmptyTypes field is not available on the .NET Compact Framework 1.0.

Properties

ApplicationBaseDirectory

Gets the base directory for this AppDomain.

public static string ApplicationBaseDirectory { get; }

Property Value

string

The base directory path for the current AppDomain.

Remarks

Gets the base directory for this AppDomain.

The value returned may be either a local file path or a URI.

ApplicationFriendlyName

Get this application's friendly name

public static string ApplicationFriendlyName { get; }

Property Value

string

The friendly name of this application as a string

Remarks

If available the name of the application is retrieved from the AppDomain using AppDomain.CurrentDomain.FriendlyName.

Otherwise the file name of the entry assembly is used.

ConfigurationFileLocation

Gets the path to the configuration file for the current AppDomain.

public static string ConfigurationFileLocation { get; }

Property Value

string

The path to the configuration file for the current AppDomain.

Remarks

The .NET Compact Framework 1.0 does not have a concept of a configuration file. For this runtime, we use the entry assembly location as the root for the configuration file name.

The value returned may be either a local file path or a URI.

CurrentThreadId

Gets the ID of the current thread.

public static int CurrentThreadId { get; }

Property Value

int

The ID of the current thread.

Remarks

On the .NET framework, the AppDomain.GetCurrentThreadId method is used to obtain the thread ID for the current thread. This is the operating system ID for the thread.

On the .NET Compact Framework 1.0 it is not possible to get the operating system thread ID for the current thread. The native method GetCurrentThreadId is implemented inline in a header file and cannot be called.

On the .NET Framework 2.0 the Thread.ManagedThreadId is used as this gives a stable id unrelated to the operating system thread ID which may change if the runtime is using fibers.

EntryAssemblyLocation

Gets the path to the file that first executed in the current AppDomain.

public static string EntryAssemblyLocation { get; }

Property Value

string

The path to the entry assembly.

Remarks

Gets the path to the file that first executed in the current AppDomain.

HostName

Get the host name or machine name for the current machine

public static string HostName { get; }

Property Value

string

The hostname or machine name

Remarks

Get the host name or machine name for the current machine

The host name (GetHostName()) or the machine name (Environment.MachineName) for the current machine, or if neither of these are available then NOT AVAILABLE is returned.

NewLine

Gets the system dependent line terminator.

public static string NewLine { get; }

Property Value

string

The system dependent line terminator.

Remarks

Gets the system dependent line terminator.

NotAvailableText

Text to output when an unsupported feature is requested.

public static string NotAvailableText { get; set; }

Property Value

string

Remarks

Use this value when an unsupported feature is requested.

The default value is NOT AVAILABLE. This value can be overridden by specifying a value for the log4net.NotAvailableText appSetting in the application's .config file.

NullText

Text to output when a null is encountered.

public static string NullText { get; set; }

Property Value

string

Remarks

Use this value to indicate a null has been encountered while outputting a string representation of an item.

The default value is (null). This value can be overridden by specifying a value for the log4net.NullText appSetting in the application's .config file.

ProcessStartTime

Get the start time for the current process.

public static DateTime ProcessStartTime { get; }

Property Value

DateTime

Remarks

This is the time at which the log4net library was loaded into the AppDomain. Due to reports of a hang in the call to System.Diagnostics.Process.StartTime this is not the start time for the current process.

The log4net library should be loaded by an application early during its startup, therefore this start time should be a good approximation for the actual start time.

Note that AppDomains may be loaded and unloaded within the same process without the process terminating, however this start time will be set per AppDomain.

Methods

AssemblyFileName(Assembly)

Gets the file name portion of the Assembly, including the extension.

public static string AssemblyFileName(Assembly myAssembly)

Parameters

myAssembly Assembly

The Assembly to get the file name for.

Returns

string

The file name of the assembly.

Remarks

Gets the file name portion of the Assembly, including the extension.

AssemblyLocationInfo(Assembly)

Gets the assembly location path for the specified assembly.

public static string AssemblyLocationInfo(Assembly myAssembly)

Parameters

myAssembly Assembly

The assembly to get the location for.

Returns

string

The location of the assembly.

Remarks

This method does not guarantee to return the correct path to the assembly. If only tries to give an indication as to where the assembly was loaded from.

AssemblyQualifiedName(Type)

Gets the fully qualified name of the Type, including the name of the assembly from which the Type was loaded.

public static string AssemblyQualifiedName(Type type)

Parameters

type Type

The Type to get the fully qualified name for.

Returns

string

The fully qualified name for the Type.

Remarks

This is equivalent to the Type.AssemblyQualifiedName property, but this method works on the .NET Compact Framework 1.0 as well as the full .NET runtime.

AssemblyShortName(Assembly)

Gets the short name of the Assembly.

public static string AssemblyShortName(Assembly myAssembly)

Parameters

myAssembly Assembly

The Assembly to get the name for.

Returns

string

The short name of the Assembly.

Remarks

The short name of the assembly is the FullName without the version, culture, or public key. i.e. it is just the assembly's file name without the extension.

Use this rather than Assembly.GetName().Name because that is not available on the Compact Framework.

Because of a FileIOPermission security demand we cannot do the obvious Assembly.GetName().Name. We are allowed to get the FullName of the assembly so we start from there and strip out just the assembly name.

ConvertToFullPath(string)

Convert a path into a fully qualified local file path.

public static string ConvertToFullPath(string path)

Parameters

path string

The path to convert.

Returns

string

The fully qualified path.

Remarks

Converts the path specified to a fully qualified path. If the path is relative it is taken as relative from the application base directory.

The path specified must be a local file path, a URI is not supported.

CreateArgumentOutOfRangeException(string, object, string)

public static ArgumentOutOfRangeException CreateArgumentOutOfRangeException(string parameterName, object actualValue, string message)

Parameters

parameterName string

The name of the parameter that caused the exception

actualValue object

The value of the argument that causes this exception

message string

The message that describes the error

Returns

ArgumentOutOfRangeException

the ArgumentOutOfRangeException object

Remarks

Create a new instance of the ArgumentOutOfRangeException class with a specified error message, the parameter name, and the value of the argument.

The Compact Framework does not support the 3 parameter constructor for the ArgumentOutOfRangeException type. This method provides an implementation that works for all platforms.

CreateCaseInsensitiveHashtable()

Creates a new case-insensitive instance of the Hashtable class with the default initial capacity.

public static Hashtable CreateCaseInsensitiveHashtable()

Returns

Hashtable

A new case-insensitive instance of the Hashtable class with the default initial capacity

Remarks

The new Hashtable instance uses the default load factor, the CaseInsensitiveHashCodeProvider, and the CaseInsensitiveComparer.

GetAppSetting(string)

Lookup an application setting

public static string GetAppSetting(string key)

Parameters

key string

the application settings key to lookup

Returns

string

the value for the key, or null

Remarks

Configuration APIs are not supported under the Compact Framework

GetTypeFromString(Assembly, string, bool, bool)

Loads the type specified in the type string.

public static Type GetTypeFromString(Assembly relativeAssembly, string typeName, bool throwOnError, bool ignoreCase)

Parameters

relativeAssembly Assembly

An assembly to load the type from.

typeName string

The name of the type to load.

throwOnError bool

Flag set to true to throw an exception if the type cannot be loaded.

ignoreCase bool

true to ignore the case of the type name; otherwise, false

Returns

Type

The type loaded or null if it could not be loaded.

Remarks

If the type name is fully qualified, i.e. if contains an assembly name in the type name, the type will be loaded from the system using Type.GetType(string,bool).

If the type name is not fully qualified it will be loaded from the specified assembly. If the type is not found in the assembly then all the loaded assemblies will be searched for the type.

GetTypeFromString(string, bool, bool)

Loads the type specified in the type string.

public static Type GetTypeFromString(string typeName, bool throwOnError, bool ignoreCase)

Parameters

typeName string

The name of the type to load.

throwOnError bool

Flag set to true to throw an exception if the type cannot be loaded.

ignoreCase bool

true to ignore the case of the type name; otherwise, false

Returns

Type

The type loaded or null if it could not be loaded.

Remarks

If the type name is fully qualified, i.e. if contains an assembly name in the type name, the type will be loaded from the system using Type.GetType(string,bool).

If the type name is not fully qualified it will be loaded from the assembly that is directly calling this method. If the type is not found in the assembly then all the loaded assemblies will be searched for the type.

GetTypeFromString(Type, string, bool, bool)

Loads the type specified in the type string.

public static Type GetTypeFromString(Type relativeType, string typeName, bool throwOnError, bool ignoreCase)

Parameters

relativeType Type

A sibling type to use to load the type.

typeName string

The name of the type to load.

throwOnError bool

Flag set to true to throw an exception if the type cannot be loaded.

ignoreCase bool

true to ignore the case of the type name; otherwise, false

Returns

Type

The type loaded or null if it could not be loaded.

Remarks

If the type name is fully qualified, i.e. if contains an assembly name in the type name, the type will be loaded from the system using Type.GetType(string,bool).

If the type name is not fully qualified, it will be loaded from the assembly containing the specified relative type. If the type is not found in the assembly then all the loaded assemblies will be searched for the type.

NewGuid()

Generate a new guid

public static Guid NewGuid()

Returns

Guid

A new Guid

Remarks

Generate a new guid

TryParse(string, out short)

Parse a string into an short value

public static bool TryParse(string s, out short val)

Parameters

s string

the string to parse

val short

out param where the parsed value is placed

Returns

bool

true if the string was able to be parsed into an integer

Remarks

Attempts to parse the string into an integer. If the string cannot be parsed then this method returns false. The method does not throw an exception.

TryParse(string, out int)

Parse a string into an int value

public static bool TryParse(string s, out int val)

Parameters

s string

the string to parse

val int

out param where the parsed value is placed

Returns

bool

true if the string was able to be parsed into an integer

Remarks

Attempts to parse the string into an integer. If the string cannot be parsed then this method returns false. The method does not throw an exception.

TryParse(string, out long)

Parse a string into an long value

public static bool TryParse(string s, out long val)

Parameters

s string

the string to parse

val long

out param where the parsed value is placed

Returns

bool

true if the string was able to be parsed into an integer

Remarks

Attempts to parse the string into an integer. If the string cannot be parsed then this method returns false. The method does not throw an exception.