Hi Vladimir

Yes, you're correct that the event log appender isn't available in the 
netstandard version of log4net because it's not cross-platform.
Right now, I don't have capacity to build one (I have outstanding work I'd like 
to do in log4net as it is), so the best suggestions I can give are:
If Log4Net.Appenders.NetCore still works adequately, then use it. Windows event 
logging has pretty-much stayed the same for many years and is unlikely to 
change because it would break a lot of things. Since the code is open-source, 
you could choose to use the nuget package (though you may have to implement 
assembly bindings) or you could copy-paste the code from 
https://github.com/robsonj/Log4Net.Appenders/blob/master/Log4Net.Appenders.NetCore/EventLogAppender.cs
 into your project. Licensing appears to be MIT from the csproj, though there's 
no LICENSE file in the repo. There's also a fork at 
https://github.com/JTOne123/Log4Net.Appenders which was updated a little more 
recently.
You could contribute, either by helping to revive Log3Net.Appenders.NetCore, or 
by creating a new package - the smaller and more accurately-named, the better, 
so I'd suggest something like Log4Net.EventLogAppender.NetCore - with only this 
appender in it and get that up at nuget.org. Sincee it brings in the extra 
package reference for System.Diagnostics.EventLog, I wouldn't want to include 
this directly in log4net, forcing more package dependencies than many people 
would want. Indeed, this is how I was first introduced to working with log4net 
- I wrote https://www.nuget.org/packages/Chillisoft.splunk4net, which isn't 
maintained any more because I left the company and it's their project (and I 
don't use splunk any more either). However, it's an example of what you could 
do.

Hope this helps
-d

On Jul 15 2022, at 10:42 am, Vladimir Ryabtsev <greatvo...@gmail.com> wrote:
> Hi,
>
> EventLogAppender is listed in the official documentation, with examples (
> https://logging.apache.org/log4net/release/config-examples.html#eventlogappender),
> but someone trying to configure this appender in a .NET (not Framework)
> application quickly finds out that this class is missing from the library.
> With .NET being now the recommended target framework by Microsoft (
> https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/versions-and-dependencies),
> it is unclear how to use this appender in .NET applications. The
> documentation does not provide any clue on that, and does not even mention
> that this appender is available only in .NET Framework version of log4net.
>
> Looking into the code, this class is commented in the netstandard/log4net
> project (
> https://git-wip-us.apache.org/repos/asf?p=logging-log4net.git;a=blob_plain;f=netstandard/log4net/log4net.xproj;hb=HEAD).
> I can guess it was made in order to avoid pulling Windows-specific
> dependencies, however I cannot find what is the alternative provided by the
> project.
>
> So far I found Log4Net.Appenders.NetCore package that fills the gap with
> the missing appender, but this package seems community-driven and abandoned
> (not maintained for 4 years), though works.
>
> Please suggest what is the best way of using EventLogAppender in modern
> .NET applications. Writing to Event Log is a requirement on my project.
>
> Thank you,
> Vladimir
>

Reply via email to