Error Logging to Event Viewer.

As many of you know how this is done, im just posting it up here for my future reference.

public static class AlertEventLogger

{
public static void LogEvent(Exception ex)
{
string sSource = “xxxxxxxx”;
string sLog = “Application”;

if (!EventLog.SourceExists(xxxxxx))
EventLog.CreateEventSource(sSource, sLog);

EventLog.WriteEntry(xxxxxx, ex.Message, EventLogEntryType.Error);
}

}

Basically i have created a static class to use for the event logging so i dont have to create a object and call the function. i can also simply put the method inside the main class and call the method to logg the event.

The source should be the name of the program/module for which you want to create the Log in the event viewer and since its application the sLog is set to the log or the event to be written in the Application Log in the event viewer.

So we pass the source, error message(system generated by the exception which we extract from the exception) and type of exception for th log the error in the event viewer.
we use the following function to log :-

EventLog.WriteEntry(sSource, ex.Message, EventLogEntryType.Error);

Other than that the first which is :-

if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);

is to make sure that a source exists with that name if it is not present we are creating an event source as such, if the source is not available then an exception will be fired.

This is how error logging is done to log errors into the Event Viewer.

SO now your wondering how to call it to the Error handling part?

Simmply call the method inside the catch phrase, as shown below.

eventlog2

 

Thanks out to Shaamil for the mentoring. 🙂

Workouts. Mistakes to Avoid.

Abs mistakes you make

A rock-hard, defined six-pack is something most men strive for. If you want a killer six-pack make sure you don’t skip your cardio sessions. Many men do when they are trying to get a six-pack, yet cardio training will help you lose that layer of fat that is currently disguising your abdominal muscles. Try to do between three and six aerobic training sessions a week, spending between 20 to 60 minutes per session doing these exercises. By doing this you will get rid of stored calories and eventually lose that belly fat that’s stopping you from getting the six-pack of your dreams.

Another mistake men make when it comes to their abs is to do with the amount of time they spend working out. A study conducted by the University of Arkansas found that those people who worked hard for short periods of time lost more abdominal fat in three months than those that worked less hard, but for longer.  So if you’ve been committing to long sessions, think about cutting back and doing more in less time. Supersets or interval training are perfect exercises to try if you want to give this a go.

Weightlifting mistakes you make

To get all of the benefits out of weightlifting you need to make sure you are taking breaks between your sets. If you do not take breaks, or don’t take breaks for long enough, you won’t get the most out of your body or the session.

This is because rest periods between sets allow your phosphagen levels to recover, which in turn enables you to have more muscular force when you next lift compared to if you had not rested. Similarly, long rest periods (between three to five minutes long) are thought to be good for those lifting heavy weights because a longer rest period can result in higher testosterone levels.

So, rest periods are great because they allow your phosphagen and testosterone levels to recover, which means you are able to lift more for longer. If you are going to start taking rests between sets make sure you change the amount of time you rest for to suit the exercise you are doing, as different lifts require different breaks.

Diet mistakes you make

If you don’t eat enough protein you are making a big diet mistake. Every man needs protein. In fact it is recommended that men should eat 56 grams of protein each day and the Institute of Medicine suggests at least 10 per cent of your daily calories should derive from protein sources.  Protein is so important because it is responsible for maintaining and building muscles. It also keeps you feeling fuller for longer. This means you won’t be so tempted to snack on unhealthy foods between meals and need to eat less at meal times. Meat, fish, eggs, cottage cheese and nuts are all excellent sources of protein. Be careful though, too much protein can negatively affect key body parts, such as your liver or your kidneys, so stick to that 56 gram recommendation.

Another diet mistake you may be making is skipping red meat altogether. In recent years there has been a lot of bad press around red meat and many believe it to be an unhealthy option. Yet red meat contains lots of nutrients and minerals that we need. For example, red meat is very high in iron and with new trimming techniques it has been found that red meat is leaner than it has been in the past. Although you shouldn’t eat too much red meat (the World Cancer Research Fund found that we should not eat more than 500g of red meat each week) a nice, fresh steak or a pork dish now and again can be good for you.

Running mistakes you make

Most runners worry about the effect running can have on their bodies, in particular their knees.  If you’re one such runner and you work out on a treadmill in an effort to avoid the negative side effects running on harder surfaces can have on your body, you are making a running mistake. Running on a treadmill does not put less strain on your knees. Instead of using a treadmill you should mix your running sessions with other cardio-based exercises, such as cycling or swimming. Varying your workouts will help reduce risk of injury and wear.

Another running mistake you may make is running steadily in all of your sessions. Running steadily is great for your endurance, but it doesn’t help you to run faster and you need to mix up your sessions, running some steadily and some quickly. Interval training is the perfect way to mix up your running workouts and ensure you progress.

Stretching mistakes you make

Do you stretch before a workout? If you do then you’re doing something wrong. Stretching before a workout is not beneficial and can damage your body. This is because stretching destabilises your muscles and therefore if you are doing an exercise that requires a certain level of stability, such as weightlifting, then you will struggle. Equally, stretching prior to a workout is bad because your muscles are cold and inelastic, meaning that stretching them could result in an injury.

Instead of stretching before your workout you should stretch afterwards and do a warm-up before rather than stretching – your muscles will be grateful.

Shocked at what you’ve found out? Here are 10 more health mistakes you might be making.

Information acquired from Yahooo! 🙂