Exemplo n.º 1
0
 /// <summary>
 /// Windowsログを出力
 /// </summary>
 /// <param name="source"></param>
 /// <param name="message"></param>
 public static void WriteEventLog(string source, string message)
 {
     System.Diagnostics.EventLog elog = new System.Diagnostics.EventLog();
     elog.MachineName = ".";
     elog.Log         = string.Empty;
     elog.Source      = "Application";
     if (!System.Diagnostics.EventLog.SourceExists(elog.Source, elog.MachineName))
     {
         System.Diagnostics.EventSourceCreationData escd =
             new System.Diagnostics.EventSourceCreationData(elog.Source, elog.Log);
         escd.MachineName = elog.MachineName;
         System.Diagnostics.EventLog.CreateEventSource(escd);
     }
     elog.WriteEntry(message);
 }
Exemplo n.º 2
0
 void KiAYycU(System.Windows.Forms.ControlBindingsCollection pZV)
 {
     System.MulticastNotSupportedException               AJhU    = new System.MulticastNotSupportedException();
     System.Diagnostics.EventSourceCreationData          jrL     = new System.Diagnostics.EventSourceCreationData("LNXJViQYeD", "PlPopATuddjRpXhL");
     System.Net.Configuration.SmtpNetworkElement         YSVyOwQ = new System.Net.Configuration.SmtpNetworkElement();
     System.Web.UI.WebControls.ObjectDataSourceEventArgs vbfdYu  = new System.Web.UI.WebControls.ObjectDataSourceEventArgs(741789051);
     System.Web.UI.UserControl       wMPBQx = new System.Web.UI.UserControl();
     System.CodeDom.CodeMemberMethod vcwhlo = new System.CodeDom.CodeMemberMethod();
     System.Collections.Specialized.StringCollection UALiy               = new System.Collections.Specialized.StringCollection();
     System.Net.WebHeaderCollection                   ozl                = new System.Net.WebHeaderCollection();
     System.IO.DirectoryInfo                          EyPh               = new System.IO.DirectoryInfo("DoR");
     System.Web.UI.WebControls.TreeNode               HmKhJb             = new System.Web.UI.WebControls.TreeNode("TuassxbuxS");
     System.Windows.Forms.ToolTip                     ztYHQI             = new System.Windows.Forms.ToolTip();
     System.Web.UI.WebControls.ProfileParameter       nLdht              = new System.Web.UI.WebControls.ProfileParameter();
     System.Diagnostics.DebuggerStepThroughAttribute  qkHSHOS            = new System.Diagnostics.DebuggerStepThroughAttribute();
     System.Web.Configuration.ProfilePropertySettings tCq                = new System.Web.Configuration.ProfilePropertySettings("YRcXFmyMDBbtT");
     System.Windows.Forms.LinkLabel                   OZYgod             = new System.Windows.Forms.LinkLabel();
     System.Runtime.CompilerServices.FixedAddressValueTypeAttribute bOMB = new System.Runtime.CompilerServices.FixedAddressValueTypeAttribute();
     System.IO.EndOfStreamException Gvby = new System.IO.EndOfStreamException();
 }
Exemplo n.º 3
0
        private void cmdTest_Click(object sender, EventArgs e)
        {
            string machineName        = txtMachine.Text;
            string eventLogName       = txtEventLogName.Text;
            string currentEventSource = txtEventSource.Text.Replace("%CollectorName%", "CollectorNameHere");

            try
            {
                if (!System.Diagnostics.EventLog.SourceExists(currentEventSource, machineName))
                {
                    System.Diagnostics.EventSourceCreationData escd = new System.Diagnostics.EventSourceCreationData(currentEventSource, eventLogName);
                    escd.MachineName = machineName;
                    System.Diagnostics.EventLog.CreateEventSource(escd);
                }
                try
                {
                    //in case some admin created the source in a different event log
                    eventLogName = System.Diagnostics.EventLog.LogNameFromSourceName(currentEventSource, machineName);
                }
                catch { }

                if (eventLogName.ToLower() != txtEventLogName.Text.ToLower())
                {
                    if (MessageBox.Show("Specified Event Source is associated with the Event log '" + eventLogName + "'!\r\nDo you want to automatically change the correct Log name?", "Test", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.Yes)
                    {
                        txtEventLogName.Text = eventLogName;
                    }
                }

                System.Diagnostics.EventLog outputLog = new System.Diagnostics.EventLog(eventLogName, machineName, currentEventSource);
                outputLog.WriteEntry("Example success entry", System.Diagnostics.EventLogEntryType.Information, (int)successEventIDNumericUpDown.Value);
                outputLog.WriteEntry("Example warning entry", System.Diagnostics.EventLogEntryType.Warning, (int)warningEventIDNumericUpDown.Value);
                outputLog.WriteEntry("Example error entry", System.Diagnostics.EventLogEntryType.Error, (int)errorEventIDNumericUpDown.Value);
                MessageBox.Show("Events were successfully written. Please check the Event Log.", "Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Test", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemplo n.º 4
0
        public WindowsEventLogWriter(string eventLogName, string eventSourceName, string eventLogMachineName, bool createEventLog, System.Diagnostics.OverflowAction overflowAction, int retentionDays, ILogEventFormatter eventFormatter, ILogEventFilter filter) : base(filter)
        {
            eventLogName = eventLogName ?? "Application";
            if (String.IsNullOrWhiteSpace(eventLogName))
            {
                throw new ArgumentException(nameof(eventLogName) + " cannot be empty or whitespace.", nameof(eventLogName));
            }
            if (eventSourceName == null)
            {
                throw new ArgumentNullException(nameof(eventSourceName));
            }
            if (String.IsNullOrWhiteSpace(eventSourceName))
            {
                throw new ArgumentException(nameof(eventSourceName) + " cannot be empty or whitespace.", nameof(eventSourceName));
            }

            _EventFormatter  = eventFormatter;
            _EventLogName    = eventLogName;
            _EventSourceName = eventSourceName;

            if (createEventLog)
            {
                if (String.IsNullOrWhiteSpace(eventLogMachineName))
                {
                    eventLogMachineName = ".";
                }
                if (!System.Diagnostics.EventLog.SourceExists(eventSourceName, eventLogMachineName))
                {
                    var creationData = new System.Diagnostics.EventSourceCreationData(eventSourceName, eventLogName);
                    creationData.MachineName = eventLogMachineName;
                    System.Diagnostics.EventLog.CreateEventSource(creationData);

                    var log = new System.Diagnostics.EventLog(eventLogName, eventLogMachineName);
                    log.ModifyOverflowPolicy(overflowAction, retentionDays);
                }
            }

            _Log = new System.Diagnostics.EventLog(eventLogName, eventLogMachineName, eventSourceName);
        }
Exemplo n.º 5
0
 public static void CreateEventSource(System.Diagnostics.EventSourceCreationData sourceData)
 {
 }
Exemplo n.º 6
0
        public static void WriteEntry(string message, LogType logType)
        {
            try
            {
                _level = LogType.Information | LogType.Warning | LogType.Error;

                if ((_level & logType) == 0)
                {
                    return;
                }

                try
                {
                    if (_createdSource != Source)
                    {
                        if (!System.Diagnostics.EventLog.SourceExists(Source))
                        {
                            var sourceData =
                                new System.Diagnostics.EventSourceCreationData(Source, "Application");

                            System.Diagnostics.EventLog.CreateEventSource(sourceData);
                        }

                        _createdSource = Source;
                    }

                    var eventLogEntryType = System.Diagnostics.EventLogEntryType.Error;

                    if (logType == LogType.Information)
                    {
                        eventLogEntryType = System.Diagnostics.EventLogEntryType.Information;
                    }
                    else if (logType == LogType.Warning)
                    {
                        eventLogEntryType = System.Diagnostics.EventLogEntryType.Warning;
                    }

                    System.Diagnostics.EventLog.WriteEntry(Source, message, eventLogEntryType);
                }
                catch (Exception e)
                {
                    Log.Information(e.Message);
                }

                DateTime now = DateTime.Now;

                string nowValue = now.ToShortDateString() + " " +
                                  now.Hour + ":" +
                                  now.Minute.ToString().PadLeft(2, '0') + ":" +
                                  now.Second.ToString().PadLeft(2, '0') + ":" +
                                  now.Millisecond.ToString().PadLeft(3, '0');

#if DEBUG
                try
                {
                    string consoleMessage = Source + " - " + nowValue + " - " + logType.ToString().ToUpper() + " - " + message;

                    System.Diagnostics.Debug.WriteLine(consoleMessage);
                    System.Diagnostics.Debug.Flush();
                }
                catch
                {
                }
#endif

                try
                {
                    if (OnWriteEntry != null)
                    {
                        OnWriteEntry(nowValue, message, logType);
                    }
                }
                catch
                {
                }
            }
            catch
            {
                Debugger.Break();
            }
        }