No Logs

Hi everyone,
It seems the Unity Cloud has problems with fetching logs. I’m not sure if it specific to me, but I can only find sporadic log entries. The only return value when calling from the API is:
{‘offset’: 0, ‘limit’: 100, ‘results’: [{‘timestamp’: ‘2024-04-04T11:12:11.23Z’, ‘severityText’: ‘INFO’, ‘severityNumber’: 9, ‘body’: ‘GetInviteLink: xxx’, ‘resourceAttributes’: {‘service.name’: ‘cloud-code’, ‘telemetry.sdk.language’: ‘dotnet’}, ‘logAttributes’: {‘code.function’: ‘MoveNext’, ‘code.namespace’: ‘xxx’, ‘faas.name’: ‘GetInviteLink’, ‘log.record.uid’: ‘a406aa58-2217-40eb-b633-362dec339d3e’, ‘unity.environmentId’: ‘yyy’, ‘unity.projectId’: ‘yyy’, ‘unity.userId’: ‘yyy’}}]}
However, there should have been many more logs.
This is the same in the dashboard.
I know that cloud functions are executing, but logs do not appear. Is this a problem with the logger setup? I use the logger interface passed to my module instance.
(I had a similar problem where recent logs where only shown when setting the range to the past 7 days.)
Best
(Sorry for the bold font, the wysiwyg forum editor displayed as white text to me)

1 Like

Hey @Iamoptimistic

We haven’t experienced any recent outages with the logging system so this might be a bug indeed. Can I ask you for a few things to help us debug:

  • Can you provide a snippet of your code where you initialize the logger in the constructor and also how you’re using it in the method itself. There might be an edge case in usage that we’ve missed. Can you also provide the version of Microsoft.Extensions.Logging that you’re using?

  • Can you post the API request that you’re making? Any format suits or if you’re using the dashboard, a screenshot of the query console would be perfect.

  • Make sure that the logs lines in your code are before any code paths that might throw exceptions and your code is executing successfully. Unfortunately, we don’t provide out of the box logs for a lot of things in Cloud Code like unhandled exceptions or timeouts, but it is something we’re looking to provide in the future.

Hopefully that should be enough for me to go by but if not we can continue to dive deeper.

Same here. Intermittent logging.

Microsoft.Extensions.Logging.Abstractions* updated to 8.0.1

Logger initialization (I also tried _logger as static):

private readonly ILogger<Match>? _logger;

public Match(ILogger<Match> logger)
{
    _logger = logger;
}

The code below only logs “Match creation started” if I remove the “Match creation completed” at the end. The service is working, as the matches are being created normally.

Looks like an intermittent issue tough, as sometimes (?) both logs are generated on UGS console.

    [CloudCodeFunction("CreateMatch")]
    public async Task<string> CreateMatch(IExecutionContext context, IGameApiClient gameApiClient, MatchBasicInfoDTO matchBasicDataDTO, List<CityDTO> citiesDTO, List<NationDTO> nationsDTO)
    {
        string matchId = Guid.NewGuid().ToString();
        _logger?.LogInformation($"Match creation started [{matchId}]");
        matchBasicDataDTO.id = matchId;
        MatchBasicInfoDO matchBasicInfoDO = MatchBasicInfoDO.Create(matchBasicDataDTO);
        List<CityDO> citiesDO = new();
        citiesDTO.ForEach(cityDTO =>
            citiesDO.Add(CityDO.Create(cityDTO))
            );
        List<NationDO> nationsDO = new();
        nationsDTO.ForEach(nationDTO =>
            nationsDO.Add(NationDO.Create(nationDTO))
        );
        List<SetItemBody> body = new()
        {
            new SetItemBody(BasicDataKey, matchBasicInfoDO),
            new SetItemBody(CityDO.CitiesDataKey, citiesDO),
            new SetItemBody(NationDO.NationsDataKey, nationsDO)
        };
        try
        {
            await gameApiClient.CloudSaveData.SetPrivateCustomItemBatchAsync(
                executionContext: context,
                accessToken: context.ServiceToken,
                projectId: context.ProjectId,
                customId: matchId,
                new SetItemBatchBody(body)
                );
        }
        catch (ApiException ex)
        {
            _logger?.LogError($"Match creation failed. Error: {ex.Message} {ex.StackTrace}");
            throw;
        }
        _logger?.LogInformation($"Match creation completed [{matchId}]");
        return matchId;
    }