1
votes

I need to create a new log file for every user after login. I also need to specify the logger configuration in the log file for every new session.

Is there any solutions available for that. Global.asax



    void Application_Start(object sender, EventArgs e) 
    {
        log4net.Config.XmlConfigurator.Configure();
        log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        logger.Info("Logger Process Started");
        logger.Info("*********************************************************");
        logger.Info("Name of The Project :" + "Reporting and Task Navigation");
        logger.Debug("Release date :" + DateTime.Today);
        logger.Debug("Release Version :" + ConfigurationManager.AppSettings.Get("releaseVersion"));
        logger.Info("Release date : " + DateTime.Today);
        logger.Info("Release Version : " + ConfigurationManager.AppSettings.Get("releaseVersion"));
        logger.Debug("Environment OS :" + Environment.OSVersion.ToString());
        logger.Debug("Frame work :" + Environment.Version);
        logger.Info("LogFileName - " + ConfigurationManager.AppSettings.Get("fileValue"));
        logger.Info("MaxSizeRollBackups -" + ConfigurationManager.AppSettings.Get("maxSizeRollBackups"));
        logger.Info("MaximumFileSize - " + ConfigurationManager.AppSettings.Get("maximumFileSize"));
        logger.Info("DatePattern - " + ConfigurationManager.AppSettings.Get("datePattern"));
        logger.Info("ConversionPattern -" + ConfigurationManager.AppSettings.Get("conversionPattern"));
        logger.Info("Logger Details assigned Successfully");
        logger.Info("End of the Logger Initialising Process");
        logger.Info("*********************************************************");
        logger.Info("");

    }

    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }

    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e) 
    {
        //log4net.LogManager.ResetConfiguration();
    }


EDIT: I tried to put the log file creation code after login success but I can't able to log the login failure data.

Any idea to create print log templates after login also to log data about the login process success and failure scenarios.

Thanks in advance

1
What about adding your logging code to the Session_Start event?Yeronimo
Thanks for your reply Yeronimo. But I need to log out the user. when i perform logout session must be cleared and new session should be created. for that each and every session i need to log in log file. Suggest me a solutionManikandan Sekar

1 Answers

0
votes

I found solution for the problem instead of loading the logger in global.asax, i loaded in the application starting page(login page) using postback so it will creates a new file whenever a new sessin is created.