Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to output Debug Logging to console #1182

Closed
richiejarvis opened this issue Sep 5, 2022 · 5 comments
Closed

Unable to output Debug Logging to console #1182

richiejarvis opened this issue Sep 5, 2022 · 5 comments

Comments

@richiejarvis
Copy link

richiejarvis commented Sep 5, 2022

I am expecting to see Logging information about the Ably connection is displayed in the console as LogLevel.Debug is set in the ClientOptions, but this doesn’t happen.

To be clearer - this code I used to test:

using IO.Ably;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

var tcs = new TaskCompletionSource();


JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
    // remove StringEnumConverter in order to avoid failures
    Converters = new List<JsonConverter>() { new StringEnumConverter() },
};


var clientOpts = new ClientOptions();
clientOpts.AutoConnect = true;
clientOpts.Key = "api-key";
clientOpts.LogLevel=LogLevel.Debug;

var realtime = new AblyRealtime(clientOpts);
Console.WriteLine("Connecting to Ably...");

realtime.Connection.On(IO.Ably.Realtime.ConnectionEvent.Connected, async x =>
{
    Console.WriteLine("Connected.");
    var channel = realtime.Channels.Get("my-test-channel");

    Console.WriteLine("Publishing to Ably...");
    var result = await channel.PublishAsync(new Message
    {
        Data = new { payload = $"published at: {DateTime.UtcNow}" },
        Encoding = "json",
        Id = Guid.NewGuid().ToString().ToLower(),
    });
    
    if (result.IsFailure)
    {
        Console.WriteLine("Failed to publish to Ably. Error:");
        Console.WriteLine(result.Error.ToString());
    }
    else
    {
        Console.WriteLine("Successfully published to Ably.");
    }
    tcs.SetResult();
});
await tcs.Task;

The resource pulled in is v1.2.9 according to the .csproj file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Ably.Healthcheck" Version="0.0.2" />
    <PackageReference Include="ably.io" Version="1.2.9" />
  </ItemGroup>

</Project>

I have run a clean, build and run:

richie@wk:~/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv$ dotnet clean
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 05/09/2022 15:41:40.
     1>Project "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/dotnetSimpleEnv.csproj" on node 1 (Clean target(s)).
     1>CoreClean:
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/dotnetSimpleEnv".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/dotnetSimpleEnv.deps.json".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/dotnetSimpleEnv.runtimeconfig.json".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/dotnetSimpleEnv.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/ref/dotnetSimpleEnv.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/dotnetSimpleEnv.pdb".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/Ably.Healthcheck.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/IO.Ably.DeltaCodec.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/IO.Ably.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/FSharp.Core.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/Microsoft.Extensions.Configuration.Abstractions.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/Microsoft.Extensions.Diagnostics.HealthChecks.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/Microsoft.Extensions.FileProviders.Abstractions.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/Microsoft.Extensions.Hosting.Abstractions.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/Microsoft.Extensions.Logging.Abstractions.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/Microsoft.Extensions.Options.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/Microsoft.Extensions.Primitives.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/Newtonsoft.Json.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/cs/FSharp.Core.resources.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/de/FSharp.Core.resources.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/es/FSharp.Core.resources.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/fr/FSharp.Core.resources.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/it/FSharp.Core.resources.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/ja/FSharp.Core.resources.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/ko/FSharp.Core.resources.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/pl/FSharp.Core.resources.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/pt-BR/FSharp.Core.resources.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/ru/FSharp.Core.resources.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/tr/FSharp.Core.resources.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/zh-Hans/FSharp.Core.resources.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/zh-Hant/FSharp.Core.resources.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/obj/Debug/net6.0/dotnetSimpleEnv.csproj.AssemblyReference.cache".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/obj/Debug/net6.0/dotnetSimpleEnv.GeneratedMSBuildEditorConfig.editorconfig".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/obj/Debug/net6.0/dotnetSimpleEnv.AssemblyInfoInputs.cache".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/obj/Debug/net6.0/dotnetSimpleEnv.AssemblyInfo.cs".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/obj/Debug/net6.0/dotnetSimpleEnv.csproj.CoreCompileInputs.cache".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/obj/Debug/net6.0/dotnetSimpleEnv.csproj.CopyComplete".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/obj/Debug/net6.0/dotnetSimpleEnv.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/obj/Debug/net6.0/ref/dotnetSimpleEnv.dll".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/obj/Debug/net6.0/dotnetSimpleEnv.pdb".
         Deleting file "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/obj/Debug/net6.0/dotnetSimpleEnv.genruntimeconfig.cache".
     1>Done Building Project "/home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/dotnetSimpleEnv.csproj" (Clean target(s)).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.34
richie@wk:~/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv$ dotnet build
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  dotnetSimpleEnv -> /home/richie/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv/bin/Debug/net6.0/dotnetSimpleEnv.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.81
richie@wk:~/git/ablyUsefulExamples/dotnet/dotnetSimpleEnv$ dotnet run
Connecting to Ably...
Connected.
Publishing to Ably...
Failed to publish to Ably. Error:
[ErrorInfo Reason: PublishAsync timeout expired. Message was not confirmed by the server]

┆Issue is synchronized with this Jira Uncategorised by Unito

@QuintinWillison
Copy link
Contributor

Relates to #1140

@s-panchekhin
Copy link

I have the same problem.

There are no logs in the debug output window.

Windows 10
Visual Studio 2022
Desktop application with .Net Framework 4.8

<Reference Include="IO.Ably, Version=1.2.9.0, Culture=neutral, PublicKeyToken=70c9e5c3d2c68b16, processorArchitecture=MSIL"> <HintPath>..\packages\ably.io.1.2.9\lib\net46\IO.Ably.dll</HintPath> </Reference>

`var clientOptions = new ClientOptions
{
Key = _apiKey,
LogLevel = LogLevel.Debug
};

var realtime = new AblyRealtime(clientOptions);

realtime.Connection.On(ConnectionEvent.Connected, args =>
{
MessageBox.Show("Realtime Connected");
});

IRealtimeChannel channel = realtime.Channels.Get("mobile");

channel.Subscribe("111222", message =>
{
MessageBox.Show(message.Name);
});`

@sacOO7
Copy link
Collaborator

sacOO7 commented Sep 6, 2022

We need to provide LogHandler that implements ILoggerSink.

        class CustomLogHandler : ILoggerSink
        {
            public void LogEvent(LogLevel level, string message)
            {
                Console.WriteLine($"Handler LogLevel : {level}, Data :{message}");
            }
        }

Update clientOptions ->

clientOpts.LogLevel = LogLevel.Debug;
clientOpts.LogHandler = new CustomLogHandler();

@s-panchekhin
Copy link

Yes, it works with LogHandler, thanks.

@QuintinWillison
Copy link
Contributor

Related, created as a result of exploration of this issue: ably/specification#14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants