serilog / serilog-sinks-xamarin

A Serilog sink that writes events to Xamarin mobile targets
Apache License 2.0
55 stars 18 forks source link

AndroidLog cannot be found #10

Closed arisliang closed 7 years ago

arisliang commented 7 years ago

Note: for support questions, please ask on StackOverflow: https://stackoverflow.com/questions/tagged/serilog . This repository's issues are reserved for feature requests and bug reports.

Do you want to request a feature or report a bug? bug

What is the current behavior?

'LoggerSinkConfiguration' does not contain a definition for 'AndroidLog' and no extension method 'AndroidLog' accepting a first argument of type 'LoggerSinkConfiguration' could be found (are you missing a using directive or an assembly reference?)

Serilog.Sinks.Xamarin.Droid (v0.1.29) has been installed on android project.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

  1. Install Serilog.Sinks.Xamarin.Droid on android project.
  2. Log.Logger = new LoggerConfiguration() .WriteTo.AndroidLog(); .CreateLogger()

What is the expected behavior? AndroidLog should be found.

What is the motivation / use case for changing the behavior? This is minimal initial setup.

Which versions of Serilog, and which platform / OS are affected by this issue? Did this work in previous versions of Serilog? Serilog: v2.4.0

Other information (e.g. stacktraces, related issues, suggestions how to fix)

ghuntley commented 7 years ago

Please share with us your packages.json from your Android application (i.e. not from your portable library)

arisliang commented 7 years ago
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.CSharp" version="4.3.0" targetFramework="monoandroid60" />
  <package id="Serilog" version="2.4.0" targetFramework="monoandroid60" />
  <package id="Serilog.Sinks.PeriodicBatching" version="2.1.0" targetFramework="monoandroid60" />
  <package id="Serilog.Sinks.Xamarin" version="0.1.29" targetFramework="monoandroid60" />
  <package id="System.Collections" version="4.3.0" targetFramework="monoandroid60" />
  <package id="System.Collections.Concurrent" version="4.3.0" targetFramework="monoandroid60" />
  <package id="System.Collections.NonGeneric" version="4.3.0" targetFramework="monoandroid60" />
  <package id="System.Dynamic.Runtime" version="4.3.0" targetFramework="monoandroid60" />
  <package id="System.Globalization" version="4.3.0" targetFramework="monoandroid60" />
  <package id="System.Linq" version="4.3.0" targetFramework="monoandroid60" />
  <package id="System.Reflection" version="4.3.0" targetFramework="monoandroid60" />
  <package id="System.Reflection.Extensions" version="4.3.0" targetFramework="monoandroid60" />
  <package id="System.Runtime" version="4.3.0" targetFramework="monoandroid60" />
  <package id="System.Runtime.Extensions" version="4.3.0" targetFramework="monoandroid60" />
  <package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="monoandroid60" />
  <package id="System.Threading" version="4.3.0" targetFramework="monoandroid60" />
  <package id="System.Threading.Timer" version="4.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.Design" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v4" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.AppCompat" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.CardView" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.MediaRouter" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.RecyclerView" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Forms" version="2.3.3.180" targetFramework="monoandroid60" />
</packages>
ghuntley commented 7 years ago

Alright, that looks good. Please share with us application boot-strap code - i.e. the file you are initializing Serilog in.

This time surround the code in ````at the start and end or link to a gist.

arisliang commented 7 years ago
using Serilog;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Xamarin.Forms;

namespace TestPCL
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            MainPage = new TestPCL.MainPage();
        }

        protected override void OnStart()
        {
            // Handle when your app starts
            InitLogger();
            Log.Logger.Information("Application started.");
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
            Log.Logger.Information("Application sleeping...");
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
            Log.Logger.Information("Application resumed.");
        }

        private void InitLogger()
        {
    //        Log.Logger = new LoggerConfiguration()
    //.WriteTo.AndroidLog()

            string appname = "Mobile Client (TEST)";
            string seq = "http://devlog.navig8.net:5341";
            Log.Logger = new LoggerConfiguration()
                .Enrich.WithProperty("Application", appname)
                .MinimumLevel.Debug()
                .WriteTo.Seq(seq, LogEventLevel.Information)

                .CreateLogger();
        }
    }
}
    //        Log.Logger = new LoggerConfiguration()
    //.WriteTo.AndroidLog()

is what gives error if uncommented.
ghuntley commented 7 years ago

You are initializing the logger from your portable library, this is incorrect. Initialize from your application. i.e. OnCreate/FinishedLaunching

arisliang commented 7 years ago

Sorry for the rookie mistake. Thanks for the prompt response!

ghuntley commented 7 years ago

nps; setup a GitHub avatar please.