Skip to content

Commit

Permalink
Explicitly use UTF-8 encoding in examples (#88)
Browse files Browse the repository at this point in the history
* Explicitly use UTF-8 encoding in examples.

log4net uses the system default encoding, which is typically Windows-1252 on .NET Framework 4.8. If the logs are forwarded to New Relic, the log forwarder expects them to be encoded in UTF-8 (without a BOM).

This change updates the documentation to help users create a better configuration by default.

* Add namespace to load encoding type class from

* Document how to use UTF-8 encoding.

log4net uses the system default encoding, which is typically Windows-1252 on .NET Framework 4.8. (.NET Core will use UTF-8 by default.) If the logs are forwarded to New Relic, the log forwarder expects them to be encoded in UTF-8 (without a BOM).

This change updates the documentation to help users create a better configuration for that platform.

* Add commented-out encoding element to log4net.config

* Revert to netcoreapp3.0 to bypass Synk problem

Co-authored-by: Alex Hemsath <[email protected]>
  • Loading branch information
bgrainger and nr-ahemsath authored Oct 28, 2020
1 parent fad22f8 commit ed91c89
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
4 changes: 2 additions & 2 deletions examples/NewRelic.LogEnrichers.Log4Net.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal static class Program

private static void Main(string[] args)
{
Console.WriteLine("Welcome to the New Relic Logging Extentions for Log4Net");
Console.WriteLine("Welcome to the New Relic Logging Extensions for Log4Net");
Console.WriteLine();

if (args.Length == 0)
Expand Down Expand Up @@ -51,7 +51,7 @@ private static void Main(string[] args)
// This log information will be visible in New Relic Logging. Since
// a transaction has not been started, this log message will not be
// associated to a specific transaction.
_logger.Info("Hello, welcome to the Log4Net Logs In Context sample app!");
_logger.Info("Hello, welcome to the Log4Net Logs In Context sample app!\u00A1");

do
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
<appender name="ToJsonFormatAppender" type="log4net.Appender.FileAppender">
<file type="log4net.Util.PatternString" value="%property{NewRelicLogFileName}" />
<param name="AppendToFile" value="true" />
<!-- uncomment the next line to get UTF-8 logs if using .NET Framework -->
<!-- <encoding type="System.Text.UTF8Encoding"/> -->
<layout type="NewRelic.LogEnrichers.Log4Net.NewRelicLayout, NewRelic.LogEnrichers.Log4Net">
</layout>
</appender>

<appender name="ToLogFormatAppender" type="log4net.Appender.FileAppender">
<file type="log4net.Util.PatternString" value="%property{StandardLogFileName}" />
<param name="AppendToFile" value="true" />
<!-- uncomment the next line to get UTF-8 logs if using .NET Framework -->
<!-- <encoding type="System.Text.UTF8Encoding"/> -->
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
</log4net>
</log4net>
4 changes: 4 additions & 0 deletions src/NewRelic.LogEnrichers.Log4Net/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Configuration of the New Relic extensions for ```log4net``` may be accomplished
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file type="log4net.Util.PatternString" value="%property{NewRelicLogFileName}" />
<param name="AppendToFile" value="true" />
<!-- uncomment the next line to get UTF-8 logs if using .NET Framework -->
<!-- <encoding type="System.Text.UTF8Encoding"/> -->
<layout type="NewRelic.LogEnrichers.Log4Net.NewRelicLayout, NewRelic.LogEnrichers.Log4Net">
</layout>
</appender>
Expand Down Expand Up @@ -80,6 +82,8 @@ The example code below creates a logger based on settings contained in an `App.c
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file type="log4net.Util.PatternString" value="%property{NewRelicLogFileName}" />
<param name="AppendToFile" value="true" />
<!-- uncomment the next line to get UTF-8 logs if using .NET Framework -->
<!-- <encoding type="System.Text.UTF8Encoding"/> -->
<layout type="NewRelic.LogEnrichers.Log4Net.NewRelicLayout, NewRelic.LogEnrichers.Log4Net">
</layout>
</appender>
Expand Down

0 comments on commit ed91c89

Please sign in to comment.