[Part 5] Logging with C# applications

Check out the codes in GitHub.

I generated a C# logging class using this command:

mc -css <Namespace_here> jytrace.man

So far, most of my event templates use an ANSI string data type which (I believe) is not supported by C#. As you can see in part 1, I use ANSI data type for my File and Function fields so that I can use __FILE__ and __FUNCTION__ as inputs in C++. Thats why I added a new event template with all fields using UNICODE data types. Again, you can refer to the whole package here for reference.

To use the logging class, I added the generated file to my project. I also added a wrapper class so I can use the CallerMemberName and CallerFilePath attributes in C#.

public static bool Verbose(
    string m,
    [CallerMemberName] string memberName = "?",
    [CallerFilePath] string srcFile = "?",
    [CallerLineNumber] int srcNum = 0)
{
    return JyTrace.ProviderJyTrace.EventWriteSimple("ETWTest", Path.GetFileName(srcFile), memberName, "Trace:", m);
}

The actual log call:

TraceCore.Verbose("Hello from CS!");

Check out part 6.

---
If you have any questions or feedback, please reach out @flowerinthenyt.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.