Archive for Giugno 16th, 2008

IPHostEntry

CodeKeep C# Feed Giugno 16th, 2008

Description: Get the name of box calling your page.

Link: http://www.codekeep.net/snippets/802fdfc2-b303-46c0-aafd-58cf945fe2ac.aspx

System.Net.IPHostEntry tmpEntry = System.Net.Dns.GetHostEntry(Request.ServerVariables["REMOTE_HOST"]);

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);
            }
        }

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);
            }
        }

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);
            }
        }