Skip to content

Commit

Permalink
Merge pull request #12 from mk3008/10-enhance-logging-functionality
Browse files Browse the repository at this point in the history
10 enhance logging functionality
  • Loading branch information
mk3008 authored Dec 17, 2023
2 parents fc8950d + 9bead94 commit db9d8b1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 27 additions & 2 deletions src/RedOrb/LoggingDbCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ private void WriteLog([CallerMemberName] string callerMethodName = "unknown")
Logger.Log(LogLevel, callerMethodName + ";\n" + GetParameterText() + CommandText + ";");
}

private void WriteExecuteResultLog(int rows, [CallerMemberName] string callerMethodName = "unknown")
{
Logger.Log(LogLevel, callerMethodName + " result : " + rows);
}

private void WriteExecuteScalarLog(object? value, [CallerMemberName] string callerMethodName = "unknown")
{
if (value == null)
{
Logger.Log(LogLevel, callerMethodName + " return : NULL");
}
else if (value.GetType() == typeof(string))
{
Logger.Log(LogLevel, callerMethodName + $" return : '{value}'");
}
else
{
Logger.Log(LogLevel, callerMethodName + $" return : {value}");
}
}

#region "implements interface"

public string CommandText { get => DbCommand.CommandText; set => DbCommand.CommandText = value; }

Check warning on line 76 in src/RedOrb/LoggingDbCommand.cs

View workflow job for this annotation

GitHub Actions / publish

Nullability of reference types in type of parameter 'value' of 'void LoggingDbCommand.CommandText.set' doesn't match implicitly implemented member 'void IDbCommand.CommandText.set' (possibly because of nullability attributes).

Check warning on line 76 in src/RedOrb/LoggingDbCommand.cs

View workflow job for this annotation

GitHub Actions / publish

Nullability of reference types in type of parameter 'value' of 'void LoggingDbCommand.CommandText.set' doesn't match implicitly implemented member 'void IDbCommand.CommandText.set' (possibly because of nullability attributes).
Expand Down Expand Up @@ -84,7 +105,9 @@ public void Dispose()
public int ExecuteNonQuery()
{
WriteLog();
return DbCommand.ExecuteNonQuery();
var val = DbCommand.ExecuteNonQuery();
WriteExecuteResultLog(val);
return val;
}

public IDataReader ExecuteReader()
Expand All @@ -102,7 +125,9 @@ public IDataReader ExecuteReader(CommandBehavior behavior)
public object? ExecuteScalar()
{
WriteLog();
return DbCommand.ExecuteScalar();
var val = DbCommand.ExecuteScalar();
WriteExecuteScalarLog(val);
return val;
}

public void Prepare()
Expand Down
2 changes: 1 addition & 1 deletion src/RedOrb/RedOrb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Copyright>Copyright (c) MSugiura 2023</Copyright>
<PackageReleaseNotes></PackageReleaseNotes>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>0.4.0</Version>
<Version>0.4.1</Version>
<Authors>MSugiura</Authors>
<Description>simply object relation mapping framework.</Description>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
Expand Down

0 comments on commit db9d8b1

Please sign in to comment.