serilog-sinks-xamarin
serilog-sinks-xamarin copied to clipboard
Use a different identifier for the Android tag instead of SourceContextPropertyName
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix, docs update
What is the current behavior? (You can also link to an open issue here)
The SourceContextPropertyName can be overwritten in some situations so the defined Tag, as described in the docs, won't work.
- Add the Android Logging as designed
.WriteTo.AndroidLog()
.Enrich.WithProperty(Constants.SourceContextPropertyName, "MyAndroidTag")
- Use in combination with Microsoft's Dependency Injection
- Register an
Microsoft.Extensions.Logging.ILoggerimplementation
services.AddSingleton<Microsoft.Extensions.Logging.ILogger>
(provider => provider.GetRequiredService<Microsoft.Extensions.Logging.ILogger<object>>());
- Notice that the SourceContextPropertyName will be "overwritten" and it'll hold "object" as value.
Snippet for my registration style to repro this:
IServiceCollection services = new ServiceCollection();
services.AddLogging(r =>
{
r.AddSerilog(logger);
});
services.AddSingleton<Microsoft.Extensions.Logging.ILogger>(provider => provider.GetRequiredService<Microsoft.Extensions.Logging.ILogger<object>>());
What is the new behavior (if this is a feature change)?
The constant used to identify the Android TAG is changed. It is introduced as part of Serilog.Sinks.Xamarin.Constants
Does this PR introduce a breaking change?
YES!
Users updating will need to add/update the enrich property for tag to be Constants.AndroidTagPropertyName
Please check if the PR fulfills these requirements
- [x] The commit follows our guidelines: https://github.com/serilog/serilog#contribute
- [ ] Tests for the changes have been added (for bug fixes / features)
- [x] Docs have been added / updated (for bug fixes / features)
Other information:
Thanks for sending this; unfortunately there's limited maintenance bandwidth for this repository, and in light of Xamarin being EOL'd no further releases are planned here. Sorry about the slow response!
Xamarin is EOL, but this package targets .NET 6 as well, meaning it can be used with .NET MAUI, Xamarin's successor -> which is actively maintained.
https://github.com/serilog/serilog-sinks-xamarin/blob/0beb06a55c5d0c91a3727f0b3de9c9c1e0c3b198/src/Serilog.Sinks.Xamarin/Serilog.Sinks.Xamarin.csproj#L7
Thanks for your reply. I think I need some help making sense of the Xamarin/MAUI/.NET landscape to figure out what needs to be done here.
For example, when I look up Android.Util.Log (which the Android version of the sink appears to use) I see "Mock Log implementation for testing on non android (sic) host":
https://learn.microsoft.com/en-us/dotnet/api/android.util.log?view=net-android-34.0#remarks
Guessing I've found the wrong docs?
In any case, "Xamarin" naming isn't going to be the best thing for this code in the future; is the right course of action to split this repository into Serilog.Sinks.Android and Serilog.Sinks.iOS, or something else along those lines? (@nickrandolph?)
Thanks for bearing with me :-)