C#C
C#10mo ago
Faker

✅ Dispose method to "dispose" file resource when using LogTo method

Hello guys, I'm trying to implement some simple logging in my DbContext. I want to write the logs in a file; when done, I need to dispose/close the file. I read that we can't use the
using
keyword because this would mean that our file stream will be closed and we won't be able to open it again (I thing, can someone please confirm please) and so we need to use the Dispose method.

C#
public override void Dispose()
    {
        base.Dispose();
        _logStream.Dispose();
    }


Here is what is written in the docs, but I have the warning CA1816. I didn't understand what exactly I need to do, I can just add this line:

GC.SuppressFinalize(this); ?
Was this page helpful?