Jayce Ooi's Paradise

Technology, mobile, photography, gaming, programming, anything

Do you know to generate error information to Windows Event Log? Most of the Windows application will output error information to Windows Event Logs if there are issues in that application. How do we do that in C#?

We need to use System.Diagnostics namespace.

Codes to generate information to output to Windows Event Logs

EventLog myLog = new EventLog();
myLog.Source = “YourApplication”;
myLog.WriteEntry(“Error Description”, EventLogEntryType.Error);

Enjoy coding… ;)

How to create and delete custom event logs in Windows using C# .NET Framework? In my latest project, I need to have a custom Windows event log to keep track of all the bugs reported by my applications. Therefore, I created an application to create this custom event log file.

First of all, you need to have using System.Diagnostics; We need to use System.Diagnostics namespace to create or remove custom event logs.

Codes to create custom event logs

EventLog.CreateEventSource(“ApplicationName”, “LogName”);

These codes will create an event log called ‘LogName’ and EventSource as ‘ApplicationName’.

Codes to delete custom event logs

EventLog.Delete(“LogName”);

Hope this will help… ;)

How to modify Windows System Registry Values with C#? As usual, you need to use Microsoft.Win32 Namespace ~ using Microsoft.Win32;. Let’s take Windows Application Event Logs values as an example. I want to change the MaxSize and Retention values in Application Event Log file by using C#.

Codes to change Windows System Registry values

RegistryKey TestEventLog = Registry.LocalMachine.OpenSubKey(“System\\CurrentControlSet\\Services\\EventLog\\Application”,true);
TestEventLog.SetValue(“MaxSize”, “102367232″, RegistryValueKind.DWord);
TestEventLog.SetValue(“Retention”, “0″, RegistryValueKind.DWord);

Above codes open Application event log and with write permission (,true). It changes both MaxSize and Retention values.
Just change the codes to suit your need. ;)

ASP.NET C# Input TextBox value by pressing Enter key. Huh? I want to get the value of the textbox without click on the submit button. But getting the textbox value by just pressing enter key on keyboard. How am I going to do so? The page just refresh if I press enter key. I want the enter key link to the submit button. Therefore, whenever I press enter key, I will get the textbox value.

Here is the solution to get it done. By adding defaultbutton variable in form or asp:Panel will solve it.

Code example

<form id=”form1″ defaultbutton=”Button1″ runat=”server”>
<div>
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
<asp:Button ID=”Button1″ runat=”server” Text=”Button” OnClick=”Button1_Click” />
<br />
<asp:Label ID=”Label1″ runat=”server” Text=”Label”></asp:Label>
<asp:Panel ID=”Panel1″ defaultbutton=”Button2″ runat=”server”>
<asp:TextBox ID=”TextBox2″ runat=”server”></asp:TextBox>
<asp:Button ID=”Button2″ runat=”server” Text=”Button” OnClick=”Button2_Click” />
<br />
<asp:Label ID=”Label2″ runat=”server” Text=”Label”></asp:Label>
</asp:Panel>
</div>
</form>

Hope this will help. The guide to convert double to int on C# source code :)

double i = 7.88;
int x = Convert.ToInt32( i );


Page 1 of 212


Featured ...

Tridea Italian Standing View Cover for Samsung Galaxy S4 Review
Urban Armor Gear Case for Samsung Galaxy S4 Review
iFrogz Samsung Galaxy S4 Cocoon Case Review
Samsung Galaxy S4 MHL 2.0 HDTV Adapter Review
Tridea Italian Wallet Flip Case for Samsung Galaxy S4 Review
OtterBox Galaxy S4 Defender Case Review
iFrogz Samsung Galaxy S4 Ultra Lean Case Review
Tridea Italian Card Pocket Flip Case for Samsung Galaxy S4 Review
64GB Samsung microSDXC Pro UHS-1 Card Review
64GB SanDisk Ultra microSDXC UHS-I Class 10 Card Review

Guide for ...

Samsung Galaxy S4
Google Nexus 4
Samsung Galaxy Note 2
Google Nexus 7
Samsung Galaxy S3
HTC One X
Amazon Kindle Fire
Samsung Galaxy S2
HTC HD2

Follow ...