I have following Synchronous an Asynchronous methods
public static void Info(string message)
{
if (_logTypes.Contains(InfoLogType))
{
string applicationName, methodName, className;
ReflectClassAndMethod(out applicationName, out className, out methodName);
Write(applicationName, "Info", className, methodName, message);
}
}
public static async void InfoAsync(string message)
{
if (_logTypes.Contains(InfoLogType))
{
string applicationName, methodName, className;
ReflectClassAndMethod(out applicationName, out className, out methodName);
await WriteAsync(applicationName, "Info", className, methodName, message);
}
}
Further my write methods are like this:
private static void Write(string applicationName, string logType, string className, string methodName, string message)
{
// construct me _event object
var collection = Database.GetCollection<Event>(typeof(Event).Name);
collection.InsertOne(_event);
}
private static Task WriteAsync(string applicationName, string logType, string className, string methodName, string message)
{
// construct my _event object
var collection = Database.GetCollection<Event>(typeof(Event).Name);
await collection.InsertOneAsync(_event);
}
Using a test console app I call these synchronous and asynchronous method as below:
static void Main(string[] args)
{
Log.Info("Synchronous write");
Log.InfoAsync(DateTime.Now.ToString(CultureInfo.InvariantCulture));
}
This will insert two documents into my Mongo Collection. but if I comment the synchronous call out, nothing will be inserted.
static void Main(string[] args)
{
//Log.Info("Synchronous write");
Log.InfoAsync(DateTime.Now.ToString(CultureInfo.InvariantCulture));
}
This will insert nothing. Why is that?