How to switch on/off logging using Log4net - log4net

I have logged all my applications transaction using Log4net. Is there any way I can disable and enable logging from a common place without altering the code written for logging.

I assume you want to toggle logging in your running application through code. I did not try it but I think that calling the following method should disable logging:
LogManager.GetRepository().ResetConfiguration();
To re-enable logging you would call
XmlConfigurator.Configure();
(or one of the other methods of the XmlConfigurator).
However there seems to be an issue with calling the Configure method repeatedly. I do not know if this would be a problem for you, but at least I warned you...

You can turn them off by changing the log4net config file. Specifically change the appender's level or global level to "OFF" value. See here for details

Assuming I understand your question, from the FAQ: http://logging.apache.org/log4net/release/faq.html
How do I completely disable all logging at runtime?
Setting the Threshold on the Hierarchy to Level OFF will disable all logging from that Hierarchy. This can be done in the log4net configuration file by setting the "threshold" attribute on the log4net configuration element to "OFF". For example:

Related

Wix installer. How to stop IIS pool

I faced with the problem in my WIX installer: how can I stop specific IIS application pool during repair, change or update?
Description: Deliver and deploy Web Application, run repair. Dialog appears that says that w3wp process locks files. In addition, because of requirements I cannot just hide that message and I cannot change Web Application.
What I tried to do:
I tried to stop service "W3SVC" with ServiceControl and it works excellent! But what I really need to do is to stop only one specific IIS pool.
I consider the way to write my own custom action to stop app pool, but as I know, I cannot schedule it before InstallValidate. Please, correct me if I'm wrong.
Please, help me overcome this issue.
You can use quiet execute custom action to shell out to appcmd to stop an app pool. You are right though, you wouldn't always be elevated prior to InstallValidate.
https://technet.microsoft.com/en-us/library/cc732742(v=ws.10).aspx
I suspect this is probably a false alarm and will resolve itself later in the installer. I would look at the various was to suppress this dialog. Maybe this would help:
WiX: Avoid showing files-in-use dialog and just prompt for reboot at end of install
First of all, please accept my great thanks!
As I understand, there are just two options to overcome the issue:
Add <ServiceControl Id="iisServiceControl" Name="W3SVC" Start="both" Stop="both" />, in case of you agree to stop the whole service
Add set property<Property Id="MSIRESTARTMANAGERCONTROL" Value="Disable" Secure="yes"
/> and schedule your custom actions to stop/start your AppPool.
I guess to use options 2 due to the requirements. BUT, as I think, the best solution would be to say that after InstallValidate validator should just ignore some kind of processes filtering them by the name.

Whether PostSharp log attribute support ansyc meathed and how to use it to write the log to a log file?

I want to know whether the log attribute of Postsharp supports ansyc method?
I want to use the log attribute to write log infos to a file.
Can you give me a demo to show me how to write log infos to a file by using log4net?
Log attribute doesn't support async methods. You can apply it to them but it doesn't understand underlying state machine so result could be quite disappointing (e.g. method exit will be logged before first await).
Adding log aspect is easy when you use PostSharp Tools for Visual Studio. Just place the caret over code element identifier (like class name or namespace) and open smart tag (or lightbulb in VS2015), select Add logging... and walk through the wizard. It is pretty straightforward.
PostSharp itself supports only logging to console and trace. As mentioned in comments you can select other backends like log4net or nlog to store log output in files (or anywhere else).
How to configure log4net is well described here and how to configure nlog is described here.

Force update Diagnostic Configuration file under wad-control-container for Azure

I would like to update the Diagnostic configuration file for the azure roles whenever I upgrade my deployment. How can I do this automatically?
From time to time, we do change our diagnostic (using code) - and upgrade the service. But whenever we upgrade the service, it is still using the old diagnostic configuration and we do not see any new logs we have configured using new code.
How can I achieve this so that whenever I upgrade my deployment, it upgrades the diagnostic configuration as well.
I wonder if you have a bug in your diagnostics updating code. If each role ran code in OnStart or Run to configure diagnostics on startup, there would be no reason that your instances wouldn't be properly configured. I tend to think that imperative code that configures diagnostics is inherently a bad idea in the long run, but it should still work. If you share the code, maybe I can spot an issue.
The best** way I have found to update and enforce configuration is to use the diagnostics.wadcfg file and update it. When you upgrade your deployment, it will use those settings if you have not overridden it in code somewhere. Contrary to Microsoft's guidance at that link, it should be the preferred method as opposed to code which must be maintained and is orthogonal to your application's purpose. Said another way - a declarative configuration file that your ops team can maintain over writing code is usually a better idea. To use this, just include it in your deployment as content and delete any existing files in wad-control-container (and remove any code that configured diagnostics). It will just configure itself from that file then when you next upgrade.
** you can also using a 3rd party SaaS monitoring to set and maintain your diagnostics config. I work on one such one, but I am guessing you want to know how to do it yourself. :)

Mule Logs not showing

I'm trying to launch a Mule application I have written, but I cant seem to get the logs to show up when I run it from the console. When I look at the log file, I see the Mule loading process (assuming I am using the app not the service mode) but then the log goes blank. Note that the log is visible when I'm using Mule Eclipse IDE.
Sounds like your app logging configuration overrides the global one, but is also not doing what you expect. Add -M-Dlog4j.debug switch to the Mule command line to see where rogue log4j config file might be coming from.
To properly log Mule messages into a log file, you should have a category definition in your log4j.properties and refer to that in your Mule flow as:
<logger level="INFO" category="your_custom_category" message="#[payload]"/>
Try to restart the entire machine. It sounds like an Eclipse problem not a problem with your program.
May be you have not properly placed the properties file and jar file.
Place
"log4j.properties" in "WEB-INF/classes"
and copy
log4jx.y.z.jar to "WEB-INF/lib".

IIS logging: don't write to log entry if match specific condition

i'm looking for some way to avoid logging some specific files like
/WebResource.axd and /ScriptResource.axd
is there any way to write some code lines in Global.asa or add some configurations to do that?
thanks
No, logging happens inside of IIS and not in the ASP.Net layer.

Resources