flynny
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
Now when I try to use Global.log I am getting 'Global' does not exist in the current context?
any ideas why?
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);
Now when I try to use Global.log I am getting 'Global' does not exist in the current context?
any ideas why?
please try only with static variable (no readonly)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;
obviously referencing the log4net dll, or would I still need to add get methods?
@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);
}
obviously referencing the log4net dll, or would I still need to add get methods?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
excellent thank you for all your help.