Unity.Logging.Log generated by 'LoggingSourceGenerator' conflicts with Unity.Logging package

9102259--1261624--upload_2023-6-24_13-46-52.png

To clarify, the conflict is in the IDE (Visual Studio) only, there is no actual compiler error inside the editor.

It messes up intellisense, auto completion, cleaning up unused using directives, and more. Compiling inside visual studio does not work (the compiler fails), so debugging is not possible either.

Edit: I posted this in the wrong forum, this should be in the Unity Transport forum… Sorry.

Then again, of course, maybe it is me…

https://docs.unity3d.com/Packages/com.unity.logging@1.0/manual/getting-started.html

The docs mention to create a separate assembly. Is this mandatory, perhaps? I’m not sure how it solves the issue, though, since I’d like to use netcode and logging in the same assembly, but maybe I’m missing something.

I’d be interested to know why it works like this if that’s the case (curiosity!).

I had to upgrade Unity Transport to 2.0.0-pre.8.

All good.

This doesn’t seem to be working entirely.

When I try to use Unity.Logging.Log.To(m_logger), the problem comes back. It works fine with Info, Warning, etc.

What version of Visual Studio are you using?

You also mention using Netcode. Do you mean Netcode for Entities? If so, do you get the same problem if using the NetDebug singleton? Or do you have a specific requirement to use custom loggers?

NetCode for GameObjects, VS 17.5.1.

I found this issue when I tried to use dependency injection instead of using statics. I was using this to forward the logs for server builds (as in here ), because the NGO docs say [quote]
Unity’s built-in logging (Debug.Log) doesn’t work for server-hosted games because it lacks the following requirements
[/quote]

It looks like maybe it’s not strictly speaking necessary: I’ve seen some logs in the file that were logged before I even set up the custom logger, so this warrants some experimentation on my side. In any case, I’m not blocked on this.

Yeah, using the logging package is certainly not required for a server-hosted game. It provides some functionality that’s typically useful for servers (log rotation, asynchronous logging), but you’ll get basic log files with Unity’s default logger too and if that’s sufficient for your use case, I’d recommend sticking with that. I’ll reach out to the documentation team to make this clearer in the documentation.

I’ll also have a look at that issue with Visual Studio. It does look very annoying.

1 Like