Warning: INSERT command denied to user 'dbo292345962'@'' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:399:\"INSERT command denied to user 'dbo292345962'@'' for table 'captcha_sessions'\nquery: INSERT into captcha_sessions (uid, sid, ip_address, timestamp, form_id, solution, status, attempts) VALUES (0, 'a3d02a97f7a07ec10375242d48807c34', '', 1591085912, 'comment_form', 'fbc6a18d06327e96532b995531d26982', 0, 0)\";s:5:\"%file\";s:62:\"/homepages/25/d199835659/htdocs/ID/modules/captcha/captcha.inc\";s:5:\"%line\";i:99;}&# in /homepages/25/d199835659/htdocs/ID/includes/database.mysql.inc on line 135
C# File Logging for Debugging | Inferno Development

C# File Logging for Debugging

Log File C#

In almost any project that requires debugging you need to have a logger that properly writes all your commands and suspicious variables into a file. Logging can save you a lot of effort because sometimes you think you understand how a built-in function works but you can be wrong. The following code can be used simply by typing Log.Logger.log("First log");. That's simple logging for debugging.


Logger Class

Just write the following code into a log.cs file in any project and you can use it.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

// Code developed by InfernoDevelopment.com

namespace Log {  
  public class Logger {
    public static void log(String message) {
        DateTime datet = DateTime.Now;
        String filePath = "Log" + datet.ToString("MM_dd") + ".log";
        if (!File.Exists(filePath)) {
          FileStream files = File.Create(filePath);
        try {
          StreamWriter sw = File.AppendText(filePath);
          sw.WriteLine(datet.ToString("MM/dd hh:mm") + "> " + message);
        } catch (Exception e) {

// Code by InfernoDevelopment.com

DateTime class provides the date and time which can be formatted using ToString. FileStream can be called to create the file if it doesn't exist yet.

StreamWriter class is useful for writing lines of text which will be written to the file using AppendText function.

The log file will be saved in the bin/debug folder or where ever your exe file is located.

Optionally you can Console.Writeline everything.

Testing of Log Class

Here's an example of it's usage:

Log.Logger.log(String.Format("<IP:{0}> SEND DATA: {1}", TCPClient.ClientIP, TCPClient.data));

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.