Link to home
Start Free TrialLog in
Avatar of flynny
flynnyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

access public variable from Global.asax file

Hi all,

I am implementing log4net to log all errors on my application.

Now i want to be able to easily log from any page in may site. So I have create the following variable in my GLobal.asax file

<script runat="server">
    public static readonly log4net.ILog log = log4net.LogManager.GetLogger
        (System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

Open in new window


Now when I try to use Global.log I am getting 'Global' does not exist in the current context?

any ideas why?
Avatar of jayakrishnabh
jayakrishnabh

please try only with static variable (no readonly)
SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of flynny

ASKER

thanks for the replies guys.

@jayakrishnabh - would Global still not be recognised in this case though?

@maz_oz2003 - ok so you are suggesting i create a class such as;

using System;
using System.Data;
using System.Linq;
using System.Web;

/// <summary>
/// Contains my site's global variables.
/// </summary>
public static class Global
{
    public static readonly log4net.ILog log = log4net.LogManager.GetLogger
        (System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
}

Open in new window


obviously referencing the log4net dll, or would I still need to add get methods?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of flynny

ASKER

excellent thank you for all your help.