You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Davyd McColl (Jira)" <ji...@apache.org> on 2022/01/24 07:56:00 UTC

[jira] (LOG4NET-586) XmlLayoutSchemaLog4j throws exception under .Net Core

    [ https://issues.apache.org/jira/browse/LOG4NET-586 ]


    Davyd McColl deleted comment on LOG4NET-586:
    --------------------------------------

was (Author: davydm):
I'm looking into this as part of another investigation. There are some options here, but none of them produce exactly the same output as before:
1. setting up namespacing for elements gives nearly the same result, but adds `xmlns:log4net="log4net"` to every `event` element:
```
<log4net:event logger="main" timestamp="2022-01-24T09:44:31.0069918+02:00" level="INFO" thread="1" domain="log4net-672" username="CODEO-LT-16\davyd" xmlns:log4net="log4net"><log4net:message>test log 6</log4net:message><log4net:properties><log4net:data name="log4net:UserName" value="CODEO-LT-16\davyd" /><log4net:data name="log4net:Identity" value="" /><log4net:data name="log4net:HostName" value="CODEO-LT-16" /></log4net:properties></log4net:event>
```
I'm not sure if this breaks something downstream, but I can easily make this the behavior for netstandard only, via `#if`
2. Stop using colons on netstandard - eg switch to using _ so that elements are, eg `log4net_event` - this is quite likely to break downstream processors
3. Write a custom xmlwriter to maintain the older behavior on newer platforms.

I'm aware that there was a PR for this, and that I closed it out because it was (a) not simple and (b) had been inactive for a very long time.

If no-one weighs in, I'm likely to go with (1) as it's the least work with the closest behavior, but I'm open for discussion. I'd like to solve this whilst looking at LOG4NET-672 as the test project I'd set up to replicate the issue as per the provided config is dotnet6, so the problem became an immediate blocker with no logs output.

> XmlLayoutSchemaLog4j throws exception under .Net Core
> -----------------------------------------------------
>
>                 Key: LOG4NET-586
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-586
>             Project: Log4net
>          Issue Type: Bug
>          Components: Other
>    Affects Versions: 2.0.8
>         Environment: .Net Core 1.1 on Windows
>            Reporter: Pierre-Yann Bridé
>            Priority: Major
>             Fix For: 2.1.0
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Hi,
> When using XmlLayoutSchemaLog4j layout with .Net Core, the following exception appears:
> {code:java}
> {quote}System.ArgumentException: Invalid name character in 'log4j:event'. The ':' character, hexadecimal value 0x0x3A, cannot be included in a name.{quote}
> {code}
> I made a copy of XmlLayoutSchemaLog4j.cs in my sources, and found the culprit:
> {code:java}
> writer.WriteStartElement("log4j:event");
> {code}
> XmlWriter.WriteStartElement is called wrongly, the namespace should be a separate argument:
> {code:java}
> writer.WriteStartElement("event", "log4j");
> {code}
> I corrected all WriteStartElement in my copy, and it now works fine. I hope that you can put this small change in the next version.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)