开发者

Is there a logging framework for .Net which supports easy programmatic configuration?

I really like log4net and it is my go-to logging framework. The only issue that I have with this framework is that it best configured with an XML file. This means that you need to know all your logging requirements befo开发者_运维技巧re start of the application.

Our application creates many connections to outside hosts. We would like to create a logger for each which logs to a separate file. So if we have 3 connections, A, B and C we would like to see logA.txt, logB.txt and logC.txt. Problem is that the number of connections we make is entirely dynamic and only know at run time. The names we choose for the files is configured in the database as well as their verbosity.

I am happy with log4net in every other area of the project. It is just to be able to dynamically create loggers for each separate connection. I have asked something similar before but how to do it log4net. The solution is a little messy and I am not sure how it will play with the rest of the logging which is setup for the project.

Is there another logging framework out there that is easier to configure programmatically. I was thinking of something like follows (for example).

ILog log = new Log();
log.FileName = "foobar.txt"
log.Level = LogLevel.Debug;


Have you considered the build in TraceSource ?

TraceSource source1 = new TraceSource("TraceSourceName");
source1.Listeners.Clear();
source1.Listeners.Add(new TextWriterTraceListener(fileName));
source1.Switch.Level = SourceLevels.Warning;

(Also don't forget to set Trace.AutoFlush to true in app.config.)

Hope you find this useful.
-Zs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜