Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SerialHandler
- {
- class Logger
- {
- public static void logSample()
- {
- // Create the source, if it does not already exist.
- if (!EventLog.SourceExists("MySource"))
- {
- EventLog.CreateEventSource("MySource", "NewSource");
- Console.WriteLine("CreatedEventSource");
- Console.WriteLine("Exiting, execute the application a second time to use the source.");
- // The source is created. Exit the application to allow it to be registered.
- return;
- }
- // Create an EventLog instance and assign its source.
- EventLog myLog = new EventLog();
- myLog.Source = "MySource";
- // Write an informational entry to the event log.
- myLog.WriteEntry("Writing to event log.");
- }
- //This is a SampleLogger that logs a string s into a log file named CustomLog, with source, MySource
- public void logSample(string s)
- {
- if(!EventLog.SourceExists("MySource",".")
- {
- EventLog.CreateEventSource("MySource", "CustomLog");
- }
- EventLog myLog = new EventLog();
- myLog.Source = "MySource";
- myLog.WriteEntry(s);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement