Exemplo n.º 1
0
        void configureLogging() {
            EventLogTraceListener eventLogListener = new EventLogTraceListener(this.EventLog);
            eventLogListener.Filter = new EventTypeFilter(SourceLevels.Information | SourceLevels.Critical | SourceLevels.Error | SourceLevels.Warning);

            EventLogTraceListener eventLogListenerError = new EventLogTraceListener(this.EventLog);
            eventLogListenerError.Filter = new EventTypeFilter(SourceLevels.Critical | SourceLevels.Error | SourceLevels.Warning);

            Logging.MachineControllerLog.Listeners.Add(eventLogListener);
            Logging.ServiceInterfaceLog.Listeners.Add(eventLogListenerError);
            VBoxWrapper.Logging.ComInterfaceLog.Listeners.Add(eventLogListenerError);
            VBoxWrapper.Logging.MachineBuildingLog.Listeners.Add(eventLogListenerError);
            VBoxWrapper.Logging.MachineLog.Listeners.Add(eventLogListenerError);

            if (Config.GetConfig().EnableTrace) {
                TextWriterTraceListener textFileListener = new TextWriterListenerWithTime(Path.Combine(Utils.GetApplicationPath(), @"VirtualBoxService.log"), "textFileLog");
                StreamWriter sw = textFileListener.Writer as StreamWriter;
                if (sw != null) sw.AutoFlush = true;

                List<TraceSource> sources = new List<TraceSource> {
                VBoxWrapper.Logging.ComInterfaceLog,
                VBoxWrapper.Logging.MachineBuildingLog,
                VBoxWrapper.Logging.MachineLog,
                Logging.MachineControllerLog,
                Logging.ServiceInterfaceLog,
            };

                foreach (var s in sources) {
                    s.Switch.Level = SourceLevels.All;
                    s.Listeners.Add(textFileListener);
                }
            }
        }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        private static void Main(string [] args)
        {
            var service = new RRLightService();

            if (Environment.UserInteractive)
            {
                // Application runs as an independent program (e.g. from console), but not as Windows service.

                // As this project uses Windows Form application as the base, it cannot run as console application.
                // Instead, all messages will be redirected to log file in "Logs" subcirectory.
                DirectoryInfo currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
                DirectoryInfo logsDirectory = currentDirectory.CreateSubdirectory("Logs");
                var listner = new TextWriterTraceListener(
                    Path.Combine(logsDirectory.FullName, string.Format("RRLightServiceDebug-{0:yy-MM-dd-HH-mm}.log", DateTime.UtcNow)));
                listner.TraceOutputOptions |= TraceOptions.DateTime;
                Trace.Listeners.Add(listner);
                Trace.AutoFlush = true;

                // Always enable verbose trace.
                TraceVerbose.Enabled = true;

                service.ManualRun();
            }
            else
            {
                // Send trace messages to Event Log.
                var listner = new EventLogTraceListener("PanoptoRRLightService");
                Trace.Listeners.Add(listner);

                // Enable verbose trace if config is set.
                TraceVerbose.Enabled = Properties.Settings.Default.EnableVerboseTrace;

                ServiceBase.Run(new ServiceBase[] { service });
            }
        }
Exemplo n.º 3
0
        private static void InitializeLogSystem()
        {
            TextWriterTraceListener traceListener = new TextWriterTraceListener(System.Console.Out);
            System.Diagnostics.Trace.Listeners.Add(traceListener);

            if(!EventLog.SourceExists("Weblab WinVM"))
                EventLog.CreateEventSource("Weblab WinVM", "Weblab Log");
            EventLog evLog = new EventLog("Weblab Log");
            evLog.Source = "Weblab WinVM";
            EventLogTraceListener evTraceListener = new EventLogTraceListener(evLog);
            System.Diagnostics.Trace.Listeners.Add(evTraceListener);
        }
Exemplo n.º 4
0
        public static void ConfigureLogging()
        {
            if (!EventLog.SourceExists("PI Fitness"))
            {
                EventLog.CreateEventSource("PI Fitness", "PI Fitness Service");
            }

            TraceSrc = new TraceSource("fitnessServiceSource");

            EventLogListener = (EventLogTraceListener)TraceSrc.Listeners["eventLogListener"];
            EventLogListener.EventLog.Log = "PI Fitness Service";
        }
        public EventLogTraceListenerAdapter(string eventSourceName)
        {
            const string myLogName = "Clickberry";

            if (!EventLog.SourceExists(eventSourceName))
            {
                EventLog.CreateEventSource(eventSourceName, myLogName);
            }

            var eventLog = new EventLog
            {
                Source = eventSourceName,
                MaximumKilobytes = 3999936L // Must be multiple of 64
            };
            _eventLogTraceListener = new EventLogTraceListener(eventLog);
        }
Exemplo n.º 6
0
        static Log()
        {
            try
            {
                if (!EventLog.SourceExists("LiveSplit"))
                    EventLog.CreateEventSource("LiveSplit", "Application");
            }
            catch { }

            try
            {
                var listener = new EventLogTraceListener("LiveSplit");
                listener.Filter = new EventTypeFilter(SourceLevels.Warning);
                Trace.Listeners.Add(listener);
            }
            catch { }
        }
Exemplo n.º 7
0
            public static LogWriter ConfigureLogWriter()
            {
                //var textFileFormatter = new TextFormatter();
                var flatFileListener = new RollingFlatFileTraceListener(@"C:\Temp\EntLibLgoFile.log");
                var asynFlatFileTraceListener = new AsynchronousTraceListenerWrapper(flatFileListener, true);

                EventLog ev = new EventLog("Application", ".", "EntLibLogging");
                EventLog eventLog = new EventLog("Application");
                var eventLogListener = new EventLogTraceListener(ev);
                var asyncEventLogListener = new AsynchronousTraceListenerWrapper(eventLogListener, true);

                var loggingConfig = new LoggingConfiguration();
                loggingConfig.AddLogSource("EntLibFlatFileLogging", SourceLevels.All, false, asynFlatFileTraceListener);
                loggingConfig.AddLogSource("EntLibEventLogLogging", SourceLevels.All, false, asyncEventLogListener);
                logWriter = new LogWriter(loggingConfig);
                return logWriter;
            }
Exemplo n.º 8
0
        public TraceConsole(AbstractConsole console, ICommand command)
        {
            Console = console;
            Command = command;
            _disposables = new List<IDisposable>();

            TraceableCommand = command as ITraceableCommand;

            if (TraceableCommand != null)
            {
                Trace.AutoFlush = true;
                TraceSource = new TraceSource(command.Name)
                                  {
                                      Switch = new SourceSwitch(Command.Name)
                                                   {
                                                       Level = SourceLevels.All
                                                   }
                                  };


                if (!string.IsNullOrEmpty(TraceableCommand.WriteFile))
                {
                    var fileName = string.Format(TraceableCommand.WriteFile.Replace("{", "{0:"),DateTime.Now);

                    var fileInfo = new FileInfo(fileName);
                    if (fileInfo.Directory != null && !fileInfo.Directory.Exists)
                    {
                        fileInfo.Directory.Create();
                    }

                    var listener = new TimestampedTextWriterTraceListener(fileName);
                    listener.Filter = new EventTypeFilter(!TraceableCommand.FileLogLevel.Any() ? GetLevel(TraceableCommand.LogLevel) : GetLevel(TraceableCommand.FileLogLevel));
                    TraceSource.Listeners.Add(listener);
                    _disposables.Add(listener);
                }
                if (TraceableCommand.WriteEventLog)
                {
                    var listener = new EventLogTraceListener(Command.Name);
                    listener.Filter = new EventTypeFilter(!TraceableCommand.EventLogLevel.Any() ? GetLevel(TraceableCommand.LogLevel) : GetLevel(TraceableCommand.EventLogLevel));
                    TraceSource.Listeners.Add(listener);
                    _disposables.Add(listener);
                }
            }
        }
Exemplo n.º 9
0
        public void TraceExamples()
        {
            var listener = new EventLogTraceListener("Valiation Examples");

            Trace.Listeners.Add(listener);
            Trace.AutoFlush = true;
            var traceStream = File.AppendText("c:\\TraceFile.txt");

            // Create a TextWriterTraceListener for the trace output file.
            TextWriterTraceListener traceListener =
                new TextWriterTraceListener(traceStream);
            Trace.Listeners.Add(traceListener);

            // Write a startup note into the trace file.
            Trace.WriteLine("Trace started " + DateTime.Now.ToString());

            Console.WriteLine("Traces");
            Trace.WriteLine("Validation Example Log");
            Console.ReadKey();
        }
Exemplo n.º 10
0
 private static void SetupEventLogTraceListener()
 {
     if (!EventLog.SourceExists(eventLogSource))
     {
         EventLog.CreateEventSource(eventLogSource, eventLogName);
     }
     myEventLog = new EventLog();
     myEventLog.Source = eventLogSource;
     myEventLogTraceListener = new EventLogTraceListener(myEventLog);
     if (myEventLog.OverflowAction != OverflowAction.OverwriteAsNeeded)
     {
         myEventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 1);
     }
     Trace.Listeners.Add(myEventLogTraceListener);
 }
Exemplo n.º 11
0
        /// Main program for Assimilation Project network discovery for Windows
        static void Main(string[] args)
        {
            mySource.Switch = new SourceSwitch("netconfig", "Error");
            mySource.Listeners.Remove("Default");
            EventLogTraceListener evl = new EventLogTraceListener("netconfig");

            //Off, Critical, Error,	Warning, Information, Verbose, ActivityTracing,	All
            evl.Filter = new EventTypeFilter(SourceLevels.All);

            mySource.Listeners.Add(evl);

            Trace.WriteLine("start netconfig");

            // build the json output string
            String jout = NetworkExplorer();

            // add the final brace
            jout += "}";

            // send to our stdout
            System.Console.WriteLine(jout);

            Trace.WriteLine("end   netconfig");
            mySource.Close();
        }
Exemplo n.º 12
0
        public static void WriteEvent(Exception passedex, String message)
        {
            StringBuilder msgout = new StringBuilder();
            if (passedex != null) {
                msgout.AppendLine(passedex.ToString());
            }

            if (message != string.Empty) {
                msgout.AppendLine(message);
            }

            EventLogTraceListener listen = new EventLogTraceListener("BannerlinkExtraction");
            Trace.Listeners.Add(listen);
            Trace.WriteLineIf(msgout.Length > 0, msgout.ToString());
        }
Exemplo n.º 13
0
        /// <summary>
        /// Set things in motion so your service can do its work.
        /// </summary>
        protected override void OnStart(string[] args)
        {
            // Event log trace
            EventLogTraceListener traceListener = new EventLogTraceListener(SyslogServiceName);
            // Add the event log trace listener to the collection.
            Trace.Listeners.Add(traceListener);

            if (ssSwitch.TraceInfo)
                Trace.WriteLine(SyslogServiceName + " starting", DbTraceListener.catInfo);

            try
            {
                // Initialize database
                string connString = Properties.Settings.Default.DbConnection;
                if (connString == null || connString.Length == 0)
                    throw new Exception("No database connection string specified");

                // Connect to database - try a few times should database not be up yet
                int tryCount = 3;
                bool connected = false;
                do
                {
                    try
                    {
                        using (OleDbConnection conn = new OleDbConnection(connString))
                        {
                            conn.Open();
                        }
                        connected = true;
                    }
                    catch (Exception ex)
                    {
                        if (ssSwitch.TraceError)
                            Trace.WriteLine("Could not connect to database: " + ex.Message,
                                DbTraceListener.catError);

                        // Sleep for 5 seconds then try again
                        Thread.Sleep(5000);
                        tryCount--;
                    }
                } while (!connected && (tryCount > 0));

                if (!connected)
                    throw new Exception("Could not connect to database");

                // Start database log
                DatabaseLog.Instance.Initialize(connString);

                // Load Configuration
                SyslogConfiguration.Instance.Initialize(connString);

                // Clear down messages periodically
                _cleanup = new SyslogMessageCleanup(SyslogConfiguration.Instance.RetentionPeriod);
                _cleanup.Initialize(connString);

                // Create server channel
                int serverPort = Properties.Settings.Default.ServerPort;
                if (serverPort <= 0)
                    throw new Exception("Invalid server port specified in configuration file");

                _channel = new HttpChannel(serverPort);
                ChannelServices.RegisterChannel(_channel, false);

                // Create shared object
                _sharedData = new SharedData();

                // Marshall object
                _obj = RemotingServices.Marshal(_sharedData, "SyslogSharedData");

                // Register for updates
                SyslogConfiguration.Instance.ConfigurationChanged +=new
                    Configuration.ConfigurationChangedDel(OnConfigurationChanged);
            }
            catch (Exception ex)
            {
                if (ssSwitch.TraceError)
                    Trace.WriteLine("Could not initialize: " + ex.Message,
                        DbTraceListener.catError);

                // Fatal - stop right now
                throw;
            }

            try
            {
                Connect();
            }
            catch (Exception ex)
            {
                if (ssSwitch.TraceError)
                    Trace.WriteLine(String.Format("Could not start to collect syslog messages on port {0}: {1}",
                        SyslogConfiguration.Instance.Port, ex.Message), DbTraceListener.catError);

                // Not fatal - probably port is in use - so carry on regardless
                // Hope for configuration
                Disconnect();
            }
        }
Exemplo n.º 14
0
        private TraceListener CreateListener(string listenerName, string typeString)
        {
            TraceListener retVal = null;
            try
            {
                nHydrateLog.LogVerbose("CreateListener(string listenerName:{0}, string typeString:{1})", listenerName, typeString);

                if (typeString == ("System.Diagnostics.DefaultTraceListener"))
                {
                    retVal = new DefaultTraceListener();
                }
                else if (typeString == ("System.Diagnostics.EventLogTraceListener"))
                {
                    retVal = new EventLogTraceListener();
                }
                else
                {
                    retVal = (TraceListener)ReflectionHelper.CreateInstance(Type.GetType(typeString));
                }

                if (retVal != null)
                {
                    retVal.Name = listenerName;
                }
                else
                {
                    throw new nHydrate.Generator.Common.Exceptions.nHydrateException(String.Format("Could not create listener - listenerName:{0}- typeString:{1})", listenerName, typeString));
                }
            }
            catch { }
            return retVal;
        }
Exemplo n.º 15
0
 // Ensure there is at least one useful listener
 private static void CheckListeners(string traceClass)
 {
     Initialized = true;
     foreach (TraceListener traceListener in Trace.Listeners) {
         if ((traceListener is TextWriterTraceListener) || (traceListener is LogWriterTraceListener)) {
             TraceInformation("Working listener called " + traceListener.Name);
             return;
         }
     }
     string path = GetDefaultLogFileLocation ();
     TraceListener listener;
     if (path != null) {
         string logfile = Path.Combine (path, traceClass + ".log");
         listener = new TextWriterTraceListener (logfile);
         TraceInformation ("Added listener writing to " + logfile);
     } else {
         listener = new EventLogTraceListener (traceClass);
         listener.Filter = new ErrorsOnlyFilter ();
         TraceInformation ("Added listener writing to event log");
     }
     Trace.Listeners.Add (listener);
     Trace.AutoFlush = true;
 }
Exemplo n.º 16
0
        protected override void OnStart(string[] args)
        {
            string logSource = "_TransportEventLog";
            if (!EventLog.SourceExists(logSource))
                EventLog.CreateEventSource(logSource, logSource);

            EventLogTraceListener myTraceListener = new EventLogTraceListener(logSource);

            // Add the event log trace listener to the collection.
            Trace.Listeners.Add(myTraceListener);

            if (args.Length > 0)
            {
                if (((ICollection<string>)args).Contains("-debug"))
                {
                    Debug = true;
                }

                if (((ICollection<string>)args).Any(a => a.Contains("-timer")))
                {
                    IEnumerable<string> timerStrings = ((ICollection<string>)args).Where(a => a.Contains("-timer"));
                    if (timerStrings.Count() == 1)
                    {
                        try {
                            string timerString = timerStrings.First();
                            int index = timerString.IndexOf('=');
                            string timerSeconds = timerString.Substring(index + 1);
                            Timer = Convert.ToInt32(timerSeconds);
                        } catch (Exception e)
                        {
                            Timer = 1;
                            EventLog.WriteEntry(SERVICE_NAME, "Error parsing the -timer command line argument.  Setting timer to 1 second.");
                        }
                    }
                }
            }

            EventLog.WriteEntry(SERVICE_NAME, "Starting...");
            Dictionary<string, string> argsMap = new Dictionary<string, string>();
            for (int i = 1; i < args.Length; i++)
            {
                argsMap.Add(args[i - 1], args[i++]);
            }

            // only allow localhost
            string listenAddress = null;
            if (!argsMap.TryGetValue("/P", out listenAddress))
            {
                listenAddress = "http://127.0.0.1:8181/";
                listenAddress = "8181";
            }

            ServiceEndpoints endpoints = new ServiceEndpoints();

            string callbackEndpoint = null;
            if (!argsMap.TryGetValue("/C", out callbackEndpoint))
            {
                callbackEndpoint = "http://localhost:8182/CloverCallback";
            }

            server = new CloverRESTServer("localhost", listenAddress, "http");// "127.0.0.1", listenAddress, "http");
            CloverRESTConnectorListener connectorListener = new CloverRESTConnectorListener();
            Console.WriteLine("callback endpoint: " + callbackEndpoint);
            connectorListener.RestClient = new RestSharp.RestClient(callbackEndpoint);
            server.ForwardToClientListener = connectorListener;
            string webSocketEndpoint = null;
            if(argsMap.TryGetValue("/L", out webSocketEndpoint))
            {
                string[] tokens = webSocketEndpoint.Split(new char[]{':'});
                if(tokens.Length != 2) {
                    throw new Exception("Invalid host and port. must be <hostname>:<port>");
                }
                string hostname = tokens[0];
                int port = int.Parse(tokens[1]);
                server.CloverConnector = new CloverConnector(new WebSocketCloverDeviceConfiguration(hostname, port, getPOSNameAndVersion(), Debug, Timer));
            }
            else
            {
                server.CloverConnector = new CloverConnector(new USBCloverDeviceConfiguration(null, getPOSNameAndVersion(), Debug, Timer));
            }
            server.CloverConnector.InitializeConnection();
            server.CloverConnector.AddCloverConnectorListener(connectorListener);
            StartRESTListener();
            server.OnAfterStart += new ToggleServerHandler(this.OnServerStart);
            server.OnStop += new ToggleServerHandler(this.OnServerStop);
        }
Exemplo n.º 17
0
 /// <summary>
 ///  Derived method to initialize trace listener to write trace data in event viewer
 /// </summary>
 /// <param name="traceSource">Trace source that holds a set of handlers</param>
 /// <param name="filterLevels">The level of trace message filtered by trace listener</param>
 /// <param name="traceOptions">Trace data options that has to be written in the trace output</param>
 /// <param name="traceListener">Trace listener object associated with the trace source</param>
 public override void InitListener(out TraceListener traceListener)
 {
     traceListener = new EventLogTraceListener("SiteController");
 }