You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by Vladimir Ryabtsev <gr...@gmail.com> on 2022/07/15 08:42:09 UTC

EventLogAppender is missing in .NET (not Framework)

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

Re: EventLogAppender is missing in .NET (not Framework)

Posted by Vladimir Ryabtsev <gr...@gmail.com>.
Thank you Davyd,

It was great to confirm that I am not missing anything.

1. Yes Log4Net.Appenders.NetCore is working fine, so I am going the way of
least resistance.
2. Currently I am not quite into .NET development, but I will take a look
if I can do that. It is easy to create a project, but I have never
submitted packages to nuget.org.

Generally I see the benefit of having that support from log4net project as
it is trusted more than individual contributors. At the very least, I think
we can modify the documentation to make it clear which components are not
supported in netstandard and what are the options to workaround it.

Kind regards,
Vladimir

On Fri, 15 Jul 2022 at 07:24, Davyd McColl <da...@gmail.com> wrote:

> 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:
>
>
>    1. 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.
>    2. 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 <gr...@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
>
>

Re: EventLogAppender is missing in .NET (not Framework)

Posted by Davyd McColl <da...@gmail.com>.
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 <gr...@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
>