← back to articles

❯ cat write-to-event-log.md

Write to Event Log

1 min readtr#C##Log#Event

.Net te basitçe Event log yazmak için özet bir extension method örneği;

public static bool WriteEventLog(string Message)
        {
            try
            {
                string sSource = "My Custom Application";
                string sLog = "Application";
                string sEvent = Message;

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

                EventLog.WriteEntry(sSource, sEvent,
EventLogEntryType.Error, 234);
                return true;
            }
            catch { return false; }
        }