' This method enables general logging. It contains parameters
' to specify a path, and Boolean values of true to include
' the application name, process ID, and events in the log.
Private Sub EnableLogging(ByVal useApp As Boolean, ByVal usePid As Boolean, ByVal useFlush As Boolean)
' Specify values for setting the registry.
Dim userRoot As String = "HKEY_LOCAL_MACHINE"
Dim subkey As String = "SOFTWARE\Microsoft\.NETCompactFramework\Diagnostics\Logging"
Dim keyName As String = userRoot + "\" + subkey
' Set the Enabled registry value.
Registry.SetValue(keyName, "Enabled", 1)
If useApp = True Then
Registry.SetValue(keyName, "UseApp", 1)
Else
Registry.SetValue(keyName, "UseApp", 0)
End If
If usePid = True Then
Registry.SetValue(keyName, "UsePid", 1)
Else
Registry.SetValue(keyName, "UsePid", 0)
End If
If useFlush = True Then
Registry.SetValue(keyName, "UseFlush", 1)
Else
Registry.SetValue(keyName, "UseFlush", 0)
End If
End Sub
' This method sets the Enabled key value to 1
' so that logging for Interoperability is enabled.
Private Sub SetInteropLogging(ByVal logOn As Boolean)
' Specify values for setting the registry.
Dim userRoot As String = "HKEY_LOCAL_MACHINE"
Dim subkey As String = "Software\Microsoft\.NETCompactFramework\Diagnostics\Logging\Interop"
Dim keyName As String = userRoot + "\" + subkey
Dim logSet As Integer
If logOn = True Then
logSet = 1
Else
logSet = 0
End If
' Set the registry value.
Try
Registry.SetValue(keyName, "Enabled", logSet)
If logOn = True Then
MsgBox("Interop Logging On")
Else
MsgBox("Interop Logging Off")
End If
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
' This method sets the Enabled key value to 1
' so that logging for class loading is enabled.
Private Sub SetLoaderLogging(ByVal logOn As Boolean)
' Specify values for setting the registry.
Dim userRoot As String = "HKEY_LOCAL_MACHINE"
Dim subkey As String = "Software\Microsoft\.NETCompactFramework\Diagnostics\Logging\Loader"
Dim keyName As String = userRoot + "\" + subkey
Dim logSet As Integer
If logOn = True Then
logSet = 1
Else
logSet = 0
End If
' Set the registry value.
Try
Registry.SetValue(keyName, "Enabled", logSet)
If logOn = True Then
MsgBox("Loader Logging On")
Else
MsgBox("Loader Loggin Off")
End If
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
' This method sets the Enabled key value to 1,
' so that logging for networking is enabled.
Private Sub SetNetworkLogging(ByVal logOn As Boolean)
' Specify values for setting the registry.
Dim userRoot As String = "HKEY_LOCAL_MACHINE"
Dim subkey As String = "Software\Microsoft\.NETCompactFramework\Diagnostics\Logging\Networking"
Dim keyName As String = userRoot + "\" + subkey
Dim logSet As Integer
If logOn = True Then
logSet = 1
Else
logSet = 0
End If
' Set the registry value.
Try
Registry.SetValue(keyName, "Enabled", logSet)
If logOn = True Then
MsgBox("Networking Logging On")
Else
MsgBox("Networking Logging Off")
End If
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
' This method disables all logging.
Private Sub DisableLogging()
' Specify values for setting the registry.
Dim userRoot As String = "HKEY_LOCAL_MACHINE"
Dim subkey As String = "SOFTWARE\Microsoft\.NETCompactFramework\Diagnostics\Logging"
Dim keyName As String = userRoot + "\" + subkey
' Set the Enabled registry value.
Registry.SetValue(keyName, "Enabled", 0)
MsgBox("Logging Disabled")
End Sub
' This method recursively examines the keys
' under the Logging subkey and writes their
' key names and values to a log file. It saves
' the information in "logsettings.txt", located
' in the directory that contains this example
' application.
Private Sub WriteLoggingSettings()
Dim sw As New StreamWriter("logsettings.txt", False)
sw.WriteLine("General Logging Settings:")
Dim rkLogging As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\.NETCompactFramework\Diagnostics\Logging")
Dim valNames As String() = rkLogging.GetValueNames()
Dim x As Integer
For x = 0 To valNames.Length
sw.WriteLine(valNames(x).ToString() + ": " + rkLogging.GetValue(valNames(x)).ToString())
Next x
sw.WriteLine()
sw.WriteLine("Interop Logging:")
Dim rkInterop As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\.NETCompactFramework\Diagnostics\Logging\Interop")
Dim interopNames As String() = rkInterop.GetValueNames()
For x = 0 To interopNames.Length
sw.WriteLine(interopNames(x).ToString() + ": " + rkInterop.GetValue(interopNames(x)).ToString())
Next x
sw.WriteLine()
sw.WriteLine("Loader Logging:")
Dim rkLoader As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\.NETCompactFramework\Diagnostics\Logging\Loader")
Dim loaderNames As String() = rkLoader.GetValueNames()
For x = 0 To loaderNames.Length
sw.WriteLine(loaderNames(x).ToString() + ": " + rkLoader.GetValue(loaderNames(x)).ToString())
Next x
sw.WriteLine()
sw.WriteLine("Networking Logging:")
Dim rkNetworking As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\.NETCompactFramework\Diagnostics\Logging\Networking")
Dim netNames As String() = rkNetworking.GetValueNames()
For x = 0 To netNames.Length
sw.WriteLine(netNames(x).ToString() + ": " + rkNetworking.GetValue(netNames(x)).ToString())
Next x
sw.Close()
End Sub
// This method enables general logging. It contains parameters
// to specify a path, and Boolean values of true to include
// the application name, process ID, and events in the log.
private void EnableLogging(bool useApp, bool usePid, bool useFlush)
{
// Specify values for setting the registry.
string userRoot = "HKEY_LOCAL_MACHINE";
string subkey = "SOFTWARE\\Microsoft\\.NETCompactFramework\\Diagnostics\\Logging";
string keyName = userRoot + "\\" + subkey;
// Set the Enabled registry value.
Registry.SetValue(keyName, "Enabled", 1);
if (useApp == true)
Registry.SetValue(keyName, "UseApp", 1);
else
Registry.SetValue(keyName, "UseApp", 0);
if (usePid == true)
Registry.SetValue(keyName, "UsePid", 1);
else
Registry.SetValue(keyName, "UsePid", 0);
if (useFlush == true)
Registry.SetValue(keyName, "UseFlush", 1);
else
Registry.SetValue(keyName, "UseFlush", 0);
}
// This method sets the Enabled key value to 1
// so that logging for Interoperability is enabled.
private void SetInteropLogging(bool logOn)
{
// Specify values for setting the registry.
string userRoot = "HKEY_LOCAL_MACHINE";
string subkey = "Software\\Microsoft\\.NETCompactFramework\\Diagnostics\\Logging\\Interop";
string keyName = userRoot + "\\" + subkey;
int logSet;
if(logOn == true)
logSet = 1;
else
logSet = 0;
// Set the registry value.
try
{
Registry.SetValue(keyName, "Enabled", logSet);
if(logOn == true)
MessageBox.Show("Interop Logging On");
else
MessageBox.Show("Interop Logging Off");
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
// This method sets the Enabled key value to 1
// so that logging for class loading is enabled.
private void SetLoaderLogging(bool logOn)
{
// Specify values for setting the registry.
string userRoot = "HKEY_LOCAL_MACHINE";
string subkey = "Software\\Microsoft\\.NETCompactFramework\\Diagnostics\\Logging\\Loader";
string keyName = userRoot + "\\" + subkey;
int logSet;
if(logOn == true)
logSet = 1;
else
logSet = 0;
// Set the registry value.
try
{
Registry.SetValue(keyName, "Enabled", logSet);
if(logOn == true)
MessageBox.Show("Loader Logging On");
else
MessageBox.Show("Loader Logging Off");
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
// This method sets the Enabled key value to 1
// so that logging for networking is enabled.
private void SetNetworkLogging(bool logOn)
{
// Specify values for setting the registry.
string userRoot = "HKEY_LOCAL_MACHINE";
string subkey = "Software\\Microsoft\\.NETCompactFramework\\Diagnostics\\Logging\\Networking";
string keyName = userRoot + "\\" + subkey;
int logSet;
if(logOn == true)
logSet = 1;
else
logSet = 0;
// Set the registry value.
try
{
Registry.SetValue(keyName, "Enabled", logSet);
if(logOn == true)
MessageBox.Show("Networking Logging On");
else
MessageBox.Show("Networking Loggin Off");
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
// This method disables all logging.
private void DisableLogging()
{
// Specify values for setting the registry.
string userRoot = "HKEY_LOCAL_MACHINE";
string subkey = "SOFTWARE\\Microsoft\\.NETCompactFramework\\Diagnostics\\Logging";
string keyName = userRoot + "\\" + subkey;
// Set the Enabled registry value.
Registry.SetValue(keyName, "Enabled", 0);
MessageBox.Show("Logging Disabled");
}
// This method recursively examines the keys
// under the Logging subkey and writes their
// key names and values to a log file. It saves
// the information in "logsettings.txt" located
// in the directory that contains this
// example application.
private void WriteLoggingSettings()
{
StreamWriter sw = new StreamWriter("logsettings.txt",false);
sw.WriteLine("General Logging Settings:");
RegistryKey rkLogging = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\.NETCompactFramework\\Diagnostics\\Logging");
string[] valNames = rkLogging.GetValueNames();
for (int x = 0; x < valNames.Length; x++)
{
sw.WriteLine(valNames[x].ToString() + ": " + rkLogging.GetValue(valNames[x]).ToString());
}
sw.WriteLine();
sw.WriteLine("Interop Logging:");
RegistryKey rkInterop = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\.NETCompactFramework\\Diagnostics\\Logging\\Interop");
string[] interopNames = rkInterop.GetValueNames();
for (int x = 0; x < interopNames.Length; x++)
{
sw.WriteLine(interopNames[x].ToString() + ": " + rkInterop.GetValue(interopNames[x]).ToString());
}
sw.WriteLine();
sw.WriteLine("Loader Logging:");
RegistryKey rkLoader = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\.NETCompactFramework\\Diagnostics\\Logging\\Loader");
string[] loaderNames = rkLoader.GetValueNames();
for (int x = 0; x < loaderNames.Length; x++)
{
sw.WriteLine(loaderNames[x].ToString() + ": " + rkLoader.GetValue(loaderNames[x]).ToString());
}
sw.WriteLine();
sw.WriteLine("Networking Logging:");
RegistryKey rkNetworking = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\.NETCompactFramework\\Diagnostics\\Logging\\Networking");
string[] netNames = rkNetworking.GetValueNames();
for (int x = 0; x < netNames.Length; x++)
{
sw.WriteLine(netNames[x].ToString() + ": " + rkNetworking.GetValue(netNames[x]).ToString());
}
sw.Close();
}