I have a C # solution in which there are multiple C # projects. I am planning to add logging in. This logging works on all projects Should be available in and prefer log4Net with rolling file logs.
With the above practice, I can think of two ways of doing this.
-
Launch the logger in the entry point of the solution (program class); Get the logger frequency & amp; Use this as a member variable for every member who requires logging.
-
Another project, Utilities & amp; Define a logging class with static logging methods This class should be started in the entry point of the solution (program class).
What could be the best solution possible?
I have such a situation that what we did uses 1 app config for all projects And uses to refer to the links.
In the app.config for your app, you set the log4net config section
& lt; ConfigSections & gt; & Lt; Section name = "log4net" type = "log4net.config.loginNetConfigurationSectionHandler, log4net" /> & Lt; / ConfigSections & gt;
and then set the appender:
& lt; Log4net & gt; & Lt; Appender Name = "RollingLogFileUpdate" type = "Log4 Net .apporder.Rolling filePaper" & gt; ...
And in each class you want to log in, enter a line like this:
Private static readonly IoLog = log4net.LogManager GetLogger (MethodBase.GetCurrentMethod () DeclaringType.);
Then each class grabs the same logger (singleton). Will this work for you?
Comments
Post a Comment