ASP.NET StreamWriter error

  • Thread starter Thread starter GTi
  • Start date Start date
G

GTi

I have created a simple logger for my ASP.NET 2.0 application.
I have this static function.
My problem is that no data is created in the test.log file.
I have added ASPNET user account administrator rights.
What am I missing here?

namespace MyNameSpace
{
public class LOG
{
public LOG()
{
}
public static void Log(string text)
{
try
{
using(StreamWriter sw = new StreamWriter("C:\\test.log"))
{
sw.Write(System.DateTime.Now.ToFileTime());
sw.Write("\t");
sw.Write(text);
sw.Write("\n");
}
}
catch { }
}
}
}
 
Post your usage of this class in your program.

Chris

--
Securing your systems is much like fighting off disease -- as long as you
maintain basic hygiene, you're likely to be okay, but you'll never be
invulnerable.

Steve Shah - Unix Systems Network Administrator
 
GTi said:
I have created a simple logger for my ASP.NET 2.0 application.
I have this static function.
My problem is that no data is created in the test.log file.
I have added ASPNET user account administrator rights.
What am I missing here?

Well, I suggest you use ASP.NET's normal logging features to log any
exceptions, instead of catching and then ignoring them. Going through
it with a debugger would help you, too.
 
public static void Log(string text)
{
try
{
using (StreamWriter sw = new StreamWriter("C:\\test.log"))
{
sw.Write(System.DateTime.Now.ToFileTime());
sw.Write("\t");
sw.Write(text);
sw.Write("\n");
sw.Flush();
sw.Close();
}
}
catch
{
// don't swallow exceptions!
}
}

--Peter
 
I'm building a library to use on ASP.NET, windows forms and windows NT
services.
So I need to build generic functions.
And I solved my problem. I needed to reboot the computer before it
worked.
I did't see any processes from user ASPNET active so I don't know why I
must reboot the computer.
 
GTi said:
I'm building a library to use on ASP.NET, windows forms and windows NT
services.
So I need to build generic functions.
And I solved my problem. I needed to reboot the computer before it
worked.
I did't see any processes from user ASPNET active so I don't know why I
must reboot the computer.

As you did change the ASPNET user rights, you should have restarted IIS for
the worker process to pick up the new access token.

Willy.
 
Back
Top