Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 25th, 2004, 11:43 AM
Registered User
 
Join Date: Jun 2003
Location: Kuala Lumpur, , Malaysia.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Event log to a text file

I intend to deploy my own version of this code to a web hosting company., but I do not have enough permission or access to write directly to the event logs.

Can anyone tech me or help me to rewrite the event log method to log to a text file?

private void LogEvent(string message)
{
  if (!EventLog.SourceExists("ThePhile.COM"))
   {
    EventLog.CreateEventSource("ThePhile.COM", "Application");
    }
   EventLog.WriteEntry("ThePhile.COM", message,
                        EventLogEntryType.Error):
}
  #2 (permalink)  
Old May 17th, 2004, 08:32 PM
Authorized User
 
Join Date: Nov 2003
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to seanmayhew
Default

Here is mine Im sure it could use improvement but it works. One thing I didnt do that I should was check for the "Logs" directory so basically you have to create the "Logs" directory first.

public class CreateLogFiles : System.Web.UI.Page
    {
    private string logFormat;
    private string fileName = "ErrorLog.txt";

    public CreateLogFiles()
    {
        //Format of the log files
        logFormat = DateTime.Now.ToShortDateString().ToString() + " " + DateTime.Now.ToLongTimeString().ToString() + " ==> ";
    }

    public void ErrorLog(string message)
    {
    string fullFilePath = Server.MapPath("/Logs/" + fileName);

    if(!File.Exists(fullFilePath))
    {
        StreamWriter sw = new StreamWriter(fullFilePath);
        sw.WriteLine(logFormat + message);
        sw.Flush();
        sw.Close();
    }
    else
    {
    using (StreamWriter sw = File.AppendText(fullFilePath))
    {
    sw.WriteLine(logFormat + message);
    sw.Flush();
    }
    }
        }
    }
}
  #3 (permalink)  
Old May 17th, 2004, 09:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The VB.NET code download has very good code for writing errors to a file, and it's explained in the .doc file that comes with the code. It only took a short time to modify that code for C#.

Be advised you have other areas to work on to make it "friendly" to hosting company sites:
1) It'll run from the root web dir, not a virt dir named ThePhile. These changes must be done in many code files, and in the DB. The most elegant solution is to store the path in one place (a .config file, or hard-coded in a class file). The DB should NEVER hold absolute dirnames in records.
2) You MUST add forms-based authentication to File Manager, and fix all "sensitive" forms (admin forms) to validate security. You'd be surprised how many of them do not! The advertisement admin page lets EVERYONE in. User admin is generally safe through the front door, but anyone can hit this page:
http://name.com/Modules/Users/Admin/....aspx?RoleID=2
3) Some areas for possible speedup: use Server.Transfer instead of Response.Redirect for all transfers to local pages ending in .aspx - this avoids a server roundtrip. Consider not using "SRC=" to register user controls. We should be able to use a classname instead (we can deploy compiled controls)
4) Put a limit on password retries, add password expiration, add a "must change" flag. IMPORTANT! Log all password failures (ideally include the user's IP)
5) The rest of my ideas are more trivial. Like having different categories of ads, and letting users select which Forums they want to participate in. Once they pick a forum, you know what kind of ads to target at that user. A DVD-only user doesn't want to see ads for books. Don't ask users for email addresses for use in forums, and remove the icon for email addresses.
6) The dumb little navigation menu on the right has always bugged me! Consider using this freeware menu:
http://www.skmmenu.com/menu/
Ideally we could dynamically create this menu. Some users might have some priviledged function that we could add to their menu after they log in.

Eric
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to log to server's event log LenexaKS Access VBA 4 March 11th, 2008 12:49 PM
Can't get Log to write the Log.txt file jnbutler BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 3 July 31st, 2007 04:04 AM
Checking the contents of a text file for log-in Seifer Classic ASP Basics 10 December 18th, 2006 12:45 PM
Event Log dkspivey ASP.NET 1.0 and 1.1 Basics 3 August 22nd, 2005 11:19 AM
AppException Class -Log Error to Event Log bekim BOOK: ASP.NET Website Programming Problem-Design-Solution 7 December 7th, 2004 01:01 PM



All times are GMT -4. The time now is 09:16 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.