Skip to content

Instantly share code, notes, and snippets.

@jzeferino
Forked from ankitvijay/Logger.cs
Created February 1, 2018 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jzeferino/3d34f21d39e4262c76e8c67697651357 to your computer and use it in GitHub Desktop.
Save jzeferino/3d34f21d39e4262c76e8c67697651357 to your computer and use it in GitHub Desktop.
CallerInfoExample
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace CallerInfoExample
{
public static class Logger
{
public static void Log(string message,
[CallerFilePath] string sourceFilePath = "",
[CallerLineNumber] int sourceLineNumber = 0,
[CallerMemberName] string callerMemberName = "")
{
Log($"[Message]: {message}; [Source File Path]: {sourceFilePath}; " +
$"[Source Line Number]: {sourceLineNumber}; [Caller Member Name]: {callerMemberName}; ");
}
private static void Log(string message)
{
Debug.WriteLine(message);
}
}
}
namespace CallerInfoExample
{
class Program
{
static void Main(string[] args)
{
Logger.Log("Testing logging inside Main() method");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment