log4net - 为什么相同的 MyLog.Debug 行在启动的某个点不起作用,但在另一点起作用?
在我的 WinForms 应用程序启动期间,我注意到有几个点(在 MainForm 渲染之前)执行“MyDataSet.GetInstance()”。对于第一个,MyLog.Debug 行出现在 VS2008 输出窗口中,但对于后面的一个,它确实可以工作并通过。
有什么可以解释这一点呢?我可以在调试时检查哪些设置,以了解为什么 MyLog.Debug 行的输出行没有出现在输出窗口中?
namespace IntranetSync
{
public class MyDataSet
{
private static readonly ILog MyLog = LogManager.GetLogger(typeof(MyDataSet));
public static MyDataSet GetInstance()
{
MyLog.Debug("MyDataSet GetInstance() =====================================");
if (myDataSet == null)
{
myDataSet = new MyDataSet();
}
return myDataSet;
}
.
.
.
附言。我一直在重新 log4net 存储库初始化所做的是将以下行作为私有变量放入我使用日志记录的类中 - 这样可以吗?
static class Program
{
private static readonly ILog MyLog = LogManager.GetLogger(typeof(MainForm));
.
.
.
public class Coordinator
{
private static readonly ILog MyLog = LogManager.GetLogger(typeof(MainForm));
.
.
.
public class MyDataSet
{
private static readonly ILog MyLog = LogManager.GetLogger(typeof(MyDataSet));
.
.
.
During startup of my WinForms application I'm noting that there are a couple of points (before the MainForm renders) that do a "MyDataSet.GetInstance()". For the first one the MyLog.Debug line comes through in the VS2008 output window, but for a later one it does work and come through.
What could explain this? What settings could I check at debug time to see why an output line for a MyLog.Debug line doesn't come out in the output window?
namespace IntranetSync
{
public class MyDataSet
{
private static readonly ILog MyLog = LogManager.GetLogger(typeof(MyDataSet));
public static MyDataSet GetInstance()
{
MyLog.Debug("MyDataSet GetInstance() =====================================");
if (myDataSet == null)
{
myDataSet = new MyDataSet();
}
return myDataSet;
}
.
.
.
PS. What I have been doing re log4net repository initialization is putting the following line as a private variables in the classes I use logging - is this OK?
static class Program
{
private static readonly ILog MyLog = LogManager.GetLogger(typeof(MainForm));
.
.
.
public class Coordinator
{
private static readonly ILog MyLog = LogManager.GetLogger(typeof(MainForm));
.
.
.
public class MyDataSet
{
private static readonly ILog MyLog = LogManager.GetLogger(typeof(MyDataSet));
.
.
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测第一次调用
GetInstance
方法发生在 log4net 存储库初始化之前。您明确初始化了您的存储库,如果是这样:在哪里?I'm guessing that the first call to the
GetInstance
method happens before the log4net repository is initialized. Du you explicitly initialize your repository, and if so: where?