incubator-stonehenge-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bende...@apache.org
Subject svn commit: r796611 - in /incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers: ./ ConsoleLogger.cs EventViewerLogger.cs ILogger.cs NullLogger.cs
Date Wed, 22 Jul 2009 04:14:33 GMT
Author: bendewey
Date: Wed Jul 22 04:14:32 2009
New Revision: 796611

URL: http://svn.apache.org/viewvc?rev=796611&view=rev
Log:
STONEHENGE-83 part2 adding Loggers, thanks Avantika, this version is much better.

Added:
    incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/
    incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/ConsoleLogger.cs
    incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/EventViewerLogger.cs
    incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/ILogger.cs
    incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/NullLogger.cs

Added: incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/ConsoleLogger.cs
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/ConsoleLogger.cs?rev=796611&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/ConsoleLogger.cs
(added)
+++ incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/ConsoleLogger.cs
Wed Jul 22 04:14:32 2009
@@ -0,0 +1,47 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+using System;
+
+namespace Trade.Utility.Loggers
+{
+    public class ConsoleLogger : ILogger
+    {
+        #region ILogger Members
+
+        public void WriteDebugMessage(string message)
+        {
+            Console.WriteLine(message);
+        }
+
+        public void WriteErrorMessage(string message)
+        {
+            Console.ForegroundColor = ConsoleColor.Red;
+            Console.WriteLine(message);
+            Console.ForegroundColor = ConsoleColor.Gray;
+        }
+
+        public void WriteException(Exception ex)
+        {
+            Console.ForegroundColor = ConsoleColor.Red;
+            Console.WriteLine(ex.ToString());
+            Console.ForegroundColor = ConsoleColor.Gray;
+        }
+
+        #endregion
+    }
+}

Added: incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/EventViewerLogger.cs
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/EventViewerLogger.cs?rev=796611&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/EventViewerLogger.cs
(added)
+++ incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/EventViewerLogger.cs
Wed Jul 22 04:14:32 2009
@@ -0,0 +1,81 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+using System;
+using System.Configuration;
+using System.Diagnostics;
+
+namespace Trade.Utility.Loggers
+{
+    public class EventViewerLogger : ILogger
+    {
+        private string logSource;
+
+        public EventViewerLogger()
+        {
+            logSource = ConfigurationManager.AppSettings.Get("EVENT_LOG");
+        }
+
+        #region ILogger Members
+
+        public void WriteDebugMessage(string message)
+        {
+            LogMessage(message, EventLogEntryType.Information, logSource);
+        }
+
+        public void WriteErrorMessage(string message)
+        {
+            LogMessage(message, EventLogEntryType.Error, logSource);
+        }
+
+        public void WriteException(Exception ex)
+        {
+            LogMessage(ex.ToString(), EventLogEntryType.Error, logSource);
+        }
+        
+        #endregion
+
+        /// <summary>Writes to event log.</summary>
+        /// <param name="message">String with message to display/log.</param>

+        /// <param name="messageType">Event Log entry type code</param> 
+        /// <param name="eventLog">The event log source name</param>
+        private void LogMessage(string message, EventLogEntryType messageType, string eventLog)
+        {
+            try
+            {
+                EventLog EventLog1 = new EventLog();
+                EventLog1.Source = eventLog;
+                EventLog1.WriteEntry(message, messageType);
+            }
+            catch (Exception e)
+            {
+                //Choice here:  sometimes Web apps will throw a security exception 
+                //writing to the event log if the source is not setup properly and the account
'Network Service'
+                //given "Full Control" to the event log to be able to write entries.  Really,
this exception should
+                //be thrown so user knows they are not getting event log info; however, to
avoid frustration
+                //for those that get it, I am simply trapping here.  Otherwise, you may wish
to uncomment this line:
+                //
+                //     throw new Exception("An exception occurred attempting to write to
the Windows Application Event Log. Please make sure the 'Network Service' account (the account
ASP.NET runs under) has write access to the Application Event Log.  You will use RegEdit to
add permissions, refer to the StockTrader Readme.html for precise instructions.\nThe specific
exception writing to the " + EVENT_LOG + " Application Log event source is: " + e.ToString());
+                //
+                //So if you catch an exception here, check e to see if a security exception.
 If so, likely need to add Network
+                //Service to EventLog permissions via regedit, current control set, services,
Event Log (select), then 
+                //from main menu choose Permissions to add Network Service with Full Control
(so ASP.NET/IIS can create/and write to).
+                string throwaway = e.Message;
+            }
+        }
+    }
+}

Added: incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/ILogger.cs
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/ILogger.cs?rev=796611&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/ILogger.cs
(added)
+++ incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/ILogger.cs
Wed Jul 22 04:14:32 2009
@@ -0,0 +1,43 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+using System;
+
+namespace Trade.Utility.Loggers
+{
+    public interface ILogger
+    {
+        /// <summary>
+        /// Writes a debug message
+        /// </summary>
+        /// <param name="message">The debug message to be logged</param>
+        void WriteDebugMessage(string message);
+
+        /// <summary>
+        /// Writes an error message
+        /// </summary>
+        /// <param name="message">The error message to be logged</param>
+        void WriteErrorMessage(string message);
+
+        /// <summary>
+        /// Writes the contents of an exception
+        /// </summary>
+        /// <param name="ex">The exception to be logged</param>
+        void WriteException(Exception ex);
+    }
+
+}

Added: incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/NullLogger.cs
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/NullLogger.cs?rev=796611&view=auto
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/NullLogger.cs
(added)
+++ incubator/stonehenge/trunk/stocktrader/dotnet/common/StockTraderUtility/Loggers/NullLogger.cs
Wed Jul 22 04:14:32 2009
@@ -0,0 +1,43 @@
+using System;
+
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+namespace Trade.Utility.Loggers
+{
+    public class NullLogger : ILogger
+    {
+        #region ILogger Members
+
+        public void WriteDebugMessage(string message)
+        {
+            // do nothing
+        }
+
+        public void WriteErrorMessage(string message)
+        {
+            // do nothing
+        }
+
+        public void WriteException(Exception ex)
+        {
+            // do nothing
+        }
+
+        #endregion
+    }
+}



Mime
View raw message