如何在另一个使用的C#脚本中使用log.info [英] How can I make log.info available in another C# script used using
本文介绍了如何在另一个使用的C#脚本中使用log.info的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码:
使用Libs;
public static readonly log4net.ILog log =
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod()。DeclaringType);
静态 void Main( string [] args)
{
Libs.Connect( www.gmail.com跨度>);
}
现在Libs NameSpace包含:
< pre lang =c#> namespace Libs
{
class Libs
{
public void Connect( string Uri)
{
log.Info( 正在连接服务器: + Uri);
}
}
}
在Libs中..log无法识别。我需要改变什么来解决这个问题?如果我在Main中使用log.Info它只是工作正常
我尝试过:
i试图改变公共空白等。
解决方案
您可以将您的Log实例放入Program中,使其在整个应用程序中全局可用。
这有点懒,但我认为对于一个真正单一资源的记录器是合理的,并且几乎不值得以更花哨的方式进行打包(单例是一个很好的选择)。
I have this code:
Using Libs;
public static readonly log4net.ILog log =
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
static void Main(string[] args)
{
Libs.Connect("www.gmail.com");
}
Now Libs NameSpace contains:
namespace Libs
{
class Libs
{
public void Connect(string Uri)
{
log.Info("Connecting to Server : " + Uri);
}
}
}
Within Libs .. "log" is not recognised. What do i need to change to fix this? If i use log.Info in Main it just works fine
What I have tried:
i tried to change public void etc.
解决方案
You can put your Log instance in Program, making it globally available throughout the app.
This is somewhat lazy but I think justified for a logger which is truly a single resource and hardly worth the effort of packaging in a more fancy way (a singleton being good alternative).
这篇关于如何在另一个使用的C#脚本中使用log.info的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文