Log4net event logging integration with Fellow Oak Dicom dicom.log4net - log4net

I'm trying to use log4net to write to the Windows Event log. I'm using the Fellow Oak DICOM log4net connector
I have setup log4net as I would in any service: the XmlConfigurator in AssemblyInfo, the *exe.logger is Copy to output, Copy Always. I have the nuget package Dicom.Log4net and the log4net package installed.
After looking at the wiki, I've added
Dicom.Log.LogManager.SetImplementation(Dicom.Log.Log4NetManager.Instance);
Can I use my log4net xml config or would I need to initialize it like the Logging Serilog example?

It turned out that the failure to identify the [XmlConfigurator] attribute in the AssemblyInfo.cs file was due to insufficient initialization of the underlying log4net LogManager, see issue #244 and pull request #248.
As of April 12, 2016, this issue has been corrected in the development branch of fo-dicom and will be incorporated in the next release.

Related

How can I suppress the initial StatusLogger error message

I am using Apache POI 5.2.2 in my application. Apache POI is using log4j2 as it's internal logging mechanism for debugging. As a result log4j-api-2.17.2.jar is a required dependency. I should note here that I am not using maven, so I downloaded the POI binary distribution and include the required dependencies in the application class path.
The logging in POI is intended for POI developers and it is not recommended for normal operation (i.e. end users). For my use case I do not want to use logging at all. However, when my application first loads one of the POI classes the following message is printed on stderr:
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
I don't want to add log4j-core, because I really don't want the logging. I really just want to suppress this message, because logging is irrelevant to the app. I would like to do this programmatically so as to avoid adding a config file for something that I am not using. I tried to do this by setting the log4j2.StatusLogger.level property to OFF but this did not make any difference (I also tried setting it to 0).
Is there a simple incantation that I can use to suppress the StatusLogger message? Or do I have to fully get in to the log4j2 world and code up a null logger?
You can disable the message by explicitly setting the logger context factory to org.apache.logging.log4j.simple.SimpleLoggerContextFactory in one of the Log4j2 property sources.
You can, e.g., add:
log4j2.loggerContextFactory = org.apache.logging.log4j.simple.SimpleLoggerContextFactory
to a log4j2.component.properties file on your classpath.
Add to the command line flags:
-Dlog4j2.loggerContextFactory=org.apache.logging.log4j.simple.SimpleLoggerContextFactory
This factory will set SimpleLogger by default.

Logging in Azure and Console app from NuGet library

looking for some advice here on developing a common logging environment for a NuGet package.
I've currently got a private NuGet package created from a C# library that works perfectly for local console apps and as such was written to log to the Windows event log.
Now I want to be able to use that package in an Azure function but of course Azure uses a different logging mechanism.
Any advice on how to create a logging overlay that allows the library to be compiled on my local PC in Visual Studio but also support logging in Azure if the package is used there?
Cheers,
Dave
I believe you are looking for the Microsoft.Extensions.Logging namespace and interface. This interface is used extensively across azure services, .Net 4+ and .Net Core. If you look for related nuget packages you will find multiple implementations for different logging scenarios and tools, including native sinks like event logs, functions, console as well as custom sinks like Splunk and Serilog.
If you separate your logging implementation from your application/package code and implement Microsoft.Extensions.Logging and adhere to the interface, then your logging interface can be easily plumbed in to many supported sinks, including functions.
A previous answer of mine provides an earlier, more manual approach to this problem. See here.

Using ServiceStack v4 with Elmah

Is there any up-to-date guide that will help with integration of Elmah into ServiceStack for logging? Anything I look, like this question is out of date since methods changed.
Ideally I would like to receive error emails like described on this link, but for start I would just love to be able to go to elmah.axd and see all unhandled errors.
I've already installed Elmah and configured web.config (which I've done using NuGet). Now I'm stuck as to what to do after doing Install-Package ServiceStack.Logging.Elmah - most of old tutorials say that I need to use NLog (which I don't want to do - since I don't want multiple logging components).
Thanks for the help!
This post should cover it: http://blog.elmah.io/logging-to-elmah-io-from-servicestack/
The post explains how to integrate with the elmah.io logger, but the method is the same for other types of ErrorLog implementations for ELMAH. Instead of installing the elmah.io NuGet package, you can install the ELMAH package, which gives you a default set of configuration in your web.config using the memory error log.

Linqpad and Log4net

I have linqpad referencing one of my own assemblies which uses log4net. When linqpad calls my assembly method I am setting my log4net logging levels to ERROR yet I see debug level messages from my assembly showing up in the linqpad results area.
Anybody know what causes this? Does Linqpad use log4net itself or have any special behavior with log4net?
LINQPad uses SharpDevelop which has a dependency on log4net, but this is kept pretty well isolated to the UI domain and shouldn't have any effect on your queries.
How are you configuring log4net? Is it programmatically or via an application config file? If it's the latter, the application config file should be named linqpad.config in order to be picked up by your queries.
I was having trouble with my configuration not being picked up. Creating a separate Linqpad.config (not editing LINQPad's own!) is the key bit of info I was missing - thanks Joe. Fantastic app by the way!

Where can I find the source code for log4j's ZeroConfSocketHubAppender?

I'm looking for a way to make log4net support zeroconf to publish logs to Apache Chainsaw (see here: Does log4net support zeroconf?). Apparently log4j can already do this using a ZeroConfSocketHubAppender.
Where might I be able to view the source for the java ZeroConfSocketHubAppender? I've looked both in the Apache Chainsaw and in the Log4j repositories but was unsuccessful.
ZeroConf is a log4j 'companion', but ZeroConfSocketHubAppender (and this companion) is no longer necessary due to the fact that most network-based appenders in log4j have ZeroConf support built-in as of log4j 1.2.16.
All you need to do to enable ZeroConf is add jmdns.jar to your classpath and set the 'advertiseViaMulticastDNS' param to 'true' in the appender configuration.
Here's the commit & log info describing the changes which improved ZeroConf support in the appenders (and receivers):
http://svn.apache.org/viewvc?view=revision&revision=924176
Here is a link to the ZeroConf page if you still want to use that
http://logging.apache.org/log4j/companions/zeroconf/source-repository.html
By the way, the svn HEAD revision of Chainsaw (which should be released soon) includes support for using the advertised ZeroConf appender information to automatically create receivers.

Resources