event log catch block

CodeKeep C# Feed Giugno 16th, 2008

Description: catch block that writes to the event log if the event log source exists.

Link: http://www.codekeep.net/snippets/d78d6529-4ae6-4979-bb36-97dec24c6958.aspx

catch (Exception ex)
        {
            if (EventLog.SourceExists(ConfigurationManager.AppSettings["EventLogSource"]))
            {
                List<string> exVarList = new List<string>();
                exVarList.Add(ex.Source + ":");
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Exception:==================");
                sb.AppendLine(ex.ToString());
                sb.AppendLine("Variable List:==============");
                foreach (string s in exVarList)
                {
                    sb.AppendLine(s);
                }
                EventLog eventLog = new EventLog(ConfigurationManager.AppSettings["EventLogName"],
                                                         ConfigurationManager.AppSettings["EventLogMachine"],
                                                         ConfigurationManager.AppSettings["EventLogSource"]);

                eventLog.WriteEntry(sb.ToString(), EventLogEntryType.Warning);
            }
        }

  • .NET
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Comments are closed.

Trackback URI |

event log catch block

CodeKeep C# Feed Giugno 16th, 2008

Description: catch block that writes to the event log if the event log source exists.

Link: http://www.codekeep.net/snippets/d78d6529-4ae6-4979-bb36-97dec24c6958.aspx

catch (Exception ex)
        {
            if (EventLog.SourceExists(ConfigurationManager.AppSettings["EventLogSource"]))
            {
                List<string> exVarList = new List<string>();
                exVarList.Add(ex.Source + ":");
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Exception:==================");
                sb.AppendLine(ex.ToString());
                sb.AppendLine("Variable List:==============");
                foreach (string s in exVarList)
                {
                    sb.AppendLine(s);
                }
                EventLog eventLog = new EventLog(ConfigurationManager.AppSettings["EventLogName"],
                                                         ConfigurationManager.AppSettings["EventLogMachine"],
                                                         ConfigurationManager.AppSettings["EventLogSource"]);

                eventLog.WriteEntry(sb.ToString(), EventLogEntryType.Warning);
            }
        }

  • .NET
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Comments are closed.

Trackback URI |

event log catch block

CodeKeep C# Feed Giugno 16th, 2008

Description: catch block that writes to the event log if the event log source exists.

Link: http://www.codekeep.net/snippets/d78d6529-4ae6-4979-bb36-97dec24c6958.aspx

catch (Exception ex)
        {
            if (EventLog.SourceExists(ConfigurationManager.AppSettings["EventLogSource"]))
            {
                List<string> exVarList = new List<string>();
                exVarList.Add(ex.Source + ":");
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Exception:==================");
                sb.AppendLine(ex.ToString());
                sb.AppendLine("Variable List:==============");
                foreach (string s in exVarList)
                {
                    sb.AppendLine(s);
                }
                EventLog eventLog = new EventLog(ConfigurationManager.AppSettings["EventLogName"],
                                                         ConfigurationManager.AppSettings["EventLogMachine"],
                                                         ConfigurationManager.AppSettings["EventLogSource"]);

                eventLog.WriteEntry(sb.ToString(), EventLogEntryType.Warning);
            }
        }

  • .NET
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Comments are closed.

Trackback URI |