public void CreateLog() { LogManager manager = LogManager.Create(); try { for (int i = 0; i < 200; i++) { var entry = new WebLogEntry() { Entered = DateTime.Now.AddDays(i * -1), ErrorLevel = ErrorLevels.Info, Message = StringUtils.RandomString(50, true), Details = StringUtils.RandomString(60, true), QueryString = StringUtils.RandomString(20, true), ErrorType = (i % 2 == 0 ? "Info" : "Error"), IpAddress = StringUtils.RandomString(12), RequestDuration = i * 1.10M }; manager.WriteEntry(entry); } } catch (Exception ex) { string message = ex.Message; } }
public void LogManagerWriteEntryTest() { WebLogEntry entry = new WebLogEntry(); entry.Message = "Testing " + DateTime.Now.ToString(); entry.ErrorLevel = ErrorLevels.Info; entry.Details = "Bogus".PadRight(3000, '.'); bool res = LogManager.Current.WriteEntry(entry); Assert.IsTrue(res, "WriteEntry failed"); }
public void DataReaderToObjectTest() { using (SqlDataAccess data = new SqlDataAccess(STR_TestDataConnection)) { IDataReader reader = data.ExecuteReader("select top 1 * from ApplicationLog"); Assert.IsNotNull(reader, "Couldn't access Data reader. " + data.ErrorMessage); Assert.IsTrue(reader.Read(), "Couldn't read from DataReader"); WebLogEntry entry = new WebLogEntry(); DataUtils.DataReaderToObject(reader, entry, null); Assert.IsNotNull(entry.Message, "Entry Message should not be null"); Assert.IsTrue(entry.ErrorLevel != ErrorLevels.None, "Entry Error level should not be None (error)"); } }
public void WriteEntry() { var entry = new WebLogEntry() { Message = "Test at " + DateTime.Now, ErrorLevel = ErrorLevels.Info }; var log = CreateLogManager(); Assert.IsTrue(log.WriteEntry(entry)); Assert.IsTrue(LogManager.Current.WriteEntry(entry)); }
public void FindByIdTest() { using (var data = new SqlDataAccess(STR_ConnectionString)) { var entry = data.Find <WebLogEntry>(1, "ApplicationLog", "Id"); Assert.IsNotNull(entry, data.ErrorMessage); Console.WriteLine(entry.Entered + " " + entry.Message); var entry2 = new WebLogEntry(); data.GetEntity(entry2, "ApplicationLog", "Id", 1); Assert.IsNotNull(entry2); Assert.AreEqual(entry2.Message, entry.Message); Console.WriteLine(entry2.Entered + " " + entry2.Message); } }
public void LogManagerWriteWebEntryTest() { WebLogEntry entry = new WebLogEntry(); entry.Message = "Testing " + DateTime.Now.ToString(); entry.ErrorLevel = ErrorLevels.Info; entry.Url = "/wwstore/admin.aspx"; entry.QueryString = "action=show"; entry.PostData = "Bogus".PadRight(3000, '.'); bool res = LogManager.Current.WriteEntry(entry); Assert.IsTrue(res, "WriteWebEntry failed"); }
public void XmlLogAdapterTest() { XmlLogAdapter adapter = new XmlLogAdapter() { ConnectionString = TestContext.DeploymentDirectory + @"\applicationlog.xml" }; WebLogEntry entry = new WebLogEntry() { Message = "Entered on: " + DateTime.Now.ToString(), ErrorLevel = ErrorLevels.Info, Details = StringUtils.RandomString(40, true) }; Assert.IsTrue(adapter.WriteEntry(entry), "Failed to write entry to log"); }
/// <summary> /// Called when the application starts executing /// /// This usually routes merely from Application_Start /// to provide consolidated configuration management all in one place. /// </summary> public static void OnApplicationStart() { HelpControl.HelpBaseUrl = "http://www.west-wind.com/WestwindWebToolkit/docs/index.htm?page="; if (LogManagerConfiguration.Current.LogWebRequests || LogManagerConfiguration.Current.LogErrors) { // create a log manager based on the LogManager config settings LogManager.Create(); WebLogEntry entry = new WebLogEntry() { Message = "Application Started", ErrorLevel = ErrorLevels.Message }; LogManager.Current.WriteEntry(entry); } }
protected void Application_EndRequest(Object sender, EventArgs e) { // Request Logging if (LogManagerConfiguration.Current.LogWebRequests) { try { WebLogEntry entry = new WebLogEntry() { ErrorLevel = ErrorLevels.Info, Message = this.Context.Request.FilePath, RequestDuration = (decimal)DateTime.Now.Subtract(Context.Timestamp).TotalMilliseconds }; entry.UpdateFromRequest(this.Context); LogManager.Current.WriteEntry(entry); } catch {; } } }
public void WriteWebLogEntryTest() { WebLogEntry entry = new WebLogEntry(); entry.ErrorLevel = ErrorLevels.Info; entry.Message = "Testing " + DateTime.Now.ToString(); entry.IpAddress = "127.0.0.1"; entry.Referrer = "http://www.west-wind.com/"; entry.Url = "/wwstore/default.aspx"; entry.QueryString = "Logout=true"; entry.RequestDuration = 0.12M; bool res = LogManager.Current.WriteEntry(entry); Assert.IsTrue(res, "Entry couldn't be written to database"); LogEntry entry2 = LogManager.Current.GetWebLogEntry(entry.Id); Assert.IsTrue(entry.Message == entry2.Message); Assert.IsTrue(entry.ErrorLevel == entry2.ErrorLevel); }
public void WriteLogEntryWithAdapterTest() { SqlLogAdapter adapter = new SqlLogAdapter(STR_ConnectionString); adapter.LogFilename = STR_TestLogFile; WebLogEntry entry = new WebLogEntry(); entry.ErrorLevel = ErrorLevels.Info; entry.Message = "Testing " + DateTime.Now.ToString(); bool res = adapter.WriteEntry(entry); //bool res = adapter.WriteEntry(entry); Assert.IsTrue(res, "Entry couldn't be written to database"); LogEntry entry2 = adapter.GetEntry(entry.Id); Assert.IsTrue(entry.Message == entry2.Message); Assert.IsTrue(entry.ErrorLevel == entry2.ErrorLevel); }
public void ExecuteDataReaderToListManualTest() { SqlDataAccess data = new SqlDataAccess(STR_ConnectionString); var swatch = new Stopwatch(); swatch.Start(); var entries = new List <WebLogEntry>(); var reader = data.ExecuteReader("select * from ApplicationLog"); while (reader.Read()) { WebLogEntry entry = new WebLogEntry(); entry.Details = reader["Details"] as string; entry.Entered = (DateTime)reader["Entered"]; entry.ErrorLevel = (ErrorLevels)reader["ErrorLevel"]; entry.Id = (int)reader["id"]; entry.IpAddress = reader["IpAddress"] as string; entry.Message = reader["Message"] as string; entry.PostData = reader["PostData"] as string; entry.QueryString = reader["QueryString"] as string; entry.Referrer = reader["Referrer"] as string; entry.RequestDuration = (decimal)reader["RequestDuration"]; entry.Url = reader["Url"] as string; entry.UserAgent = reader["UserAgent"] as string; entries.Add(entry); } reader.Close(); swatch.Stop(); Console.WriteLine(swatch.ElapsedMilliseconds); Console.WriteLine(entries.Count); }
protected override void Seed(WebStoreContext context) { try { var cust = new Customer() { FirstName = "Rick", LastName = "Strahl", Company = "West Wind", Address = "32 Kaiea Place\r\nPaia, HI", }; context.Customers.Add(cust); int res = context.SaveChanges(); var order = new Order() { Customer = cust, OrderId = "Order1", }; var lItem = new LineItem() { Sku = "WCONNECT", Description = "West wind Web Connection", Quantity = 1, Price = 399.99M, OrderId = order.Id }; lItem.Total = lItem.Quantity * lItem.Price; order.LineItems.Add(lItem); lItem = new LineItem() { Sku = "WWHELP", Description = "West Wind Html Help Builder", Quantity = 1, Price = 299.99M, OrderId = order.Id }; lItem.Total = lItem.Quantity * lItem.Price; order.LineItems.Add(lItem); context.Orders.Add(order); res = context.SaveChanges(); // add 100 random customers for (int i = 0; i < 550; i++) { cust = new Customer() { FirstName = StringUtils.RandomString(20), LastName = StringUtils.RandomString(20), Company = StringUtils.RandomString(25), Updated = DateTime.Now.AddDays(i * -1) }; order = new Order() { Entered = DateTime.Now.AddDays(i * -1), OrderId = StringUtils.RandomString(10) }; cust.Orders.Add(order); lItem = new LineItem() { Sku = "WCONNECT", Description = "West wind Web Connection", Quantity = 1, Price = 399.99M, OrderId = order.Id }; lItem.Total = lItem.Quantity * lItem.Price; order.LineItems.Add(lItem); lItem = new LineItem() { Sku = "WWHELP", Description = "West Wind Html Help Builder", Quantity = 1, Price = 299.99M, OrderId = order.Id }; lItem.Total = lItem.Quantity * lItem.Price; order.LineItems.Add(lItem); context.Customers.Add(cust); context.SaveChanges(); } LogManager manager = LogManager.Create(); for (int i = 0; i < 250; i++) { var entry = new WebLogEntry() { Entered = DateTime.Now.AddDays(i * -1), ErrorLevel = ErrorLevels.Info, Message = StringUtils.RandomString(50, true), Details = StringUtils.RandomString(60, true), QueryString = StringUtils.RandomString(20, true), ErrorType = (i % 2 == 0 ? "Info" : "Error"), IpAddress = StringUtils.RandomString(12), RequestDuration = i * 1.10M }; manager.WriteEntry(entry); } } catch (Exception ex) { string message = ex.Message; } }
protected void Application_Error() { try { Exception serverException = Server.GetLastError(); WebErrorHandler errorHandler; // Try to log the inner Exception since that's what // contains the 'real' error. if (serverException.InnerException != null) { serverException = serverException.InnerException; } errorHandler = new WebErrorHandler(serverException); // MUST clear out any previous response in case error occurred in a view // that already started rendering Response.Clear(); // Log the error if specified if (LogManagerConfiguration.Current.LogErrors) { errorHandler.Parse(); //try //{ WebLogEntry entry = new WebLogEntry(serverException, this.Context); entry.Details = errorHandler.ToString(); LogManager.Current.WriteEntry(entry); //} //catch { /* Log Error shouldn't kill the error handler */ } } // Retrieve the detailed String information of the Error string ErrorDetail = errorHandler.ToString(); // Optionally email it to the Admin contacts set up in WebStoreConfig if (!string.IsNullOrEmpty(App.Configuration.ErrorEmailAddress)) { AppWebUtils.SendAdminEmail(App.Configuration.ApplicationTitle + "Error: " + Request.RawUrl, ErrorDetail, "", App.Configuration.ErrorEmailAddress); } // Debug modes handle different error display mechanisms // Default - default ASP.Net - depends on web.config settings // Developer - display a generic application error message with no error info // User - display a detailed error message with full error info independent of web.config setting if (App.Configuration.DebugMode == DebugModes.DeveloperErrorMessage) { Server.ClearError(); Response.TrySkipIisCustomErrors = true; ErrorController.ShowErrorPage("Application Error", "<div class='codedisplay'><pre id='Code'>" + HttpUtility.HtmlEncode(ErrorDetail) + "</pre></div>"); return; } else if (App.Configuration.DebugMode == DebugModes.ApplicationErrorMessage) { string StockMessage = "The Server Administrator has been notified and the error logged.<p>" + "Please continue by either clicking the back button or by returning to the home page.</p>" + "<p><b><a href='" + Request.ApplicationPath + "'>Click here to continue...</a></b></p>"; // Handle some stock errors that may require special error pages HttpException httpException = serverException as HttpException; if (httpException != null) { int HttpCode = httpException.GetHttpCode(); Server.ClearError(); if (HttpCode == 404) // Page Not Found { Response.StatusCode = 404; ErrorController.ShowErrorPage("Page not found", "You've accessed an invalid page on this Web server. " + StockMessage, null); return; } if (HttpCode == 401) // Access Denied { Response.StatusCode = 401; ErrorController.ShowErrorPage("Access Denied", "You've accessed a resource that requires a valid login. " + StockMessage); return; } } // Display a generic error message Server.ClearError(); Response.StatusCode = 500; Response.TrySkipIisCustomErrors = true; ErrorController.ShowErrorPage("Application Error", "We're sorry, but an unhandled error occurred on the server. " + StockMessage); return; } return; } catch (Exception ex) { // Failure in the attempt to report failure - try to email if (!string.IsNullOrEmpty(App.Configuration.ErrorEmailAddress)) { AppWebUtils.SendAdminEmail(App.Configuration.ApplicationTitle + "Error: " + Request.RawUrl, "Application_Error failed!\r\n\r\n" + ex.ToString(), "", App.Configuration.ErrorEmailAddress); } // and display an error message Server.ClearError(); Response.StatusCode = 500; Response.TrySkipIisCustomErrors = true; ErrorController.ShowErrorPage("Application Error Handler Failed", "The application Error Handler failed with an exception." + (App.Configuration.DebugMode == DebugModes.DeveloperErrorMessage ? "<pre>" + ex.ToString() + "</pre>" : ""), null); } }