Skip to content

Commit

Permalink
Added: log execution end attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
yagasoft committed Oct 2, 2021
1 parent 14533be commit 1d3543d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CrmLogger.Fody/CrmLogger.Fody.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<package>
<metadata>
<id>CrmLogger.Fody</id>
<version>1.5.1</version>
<version>1.5.2</version>
<authors>Ahmed Elsawalhy</authors>
<owners>Ahmed Elsawalhy</owners>
<projectUrl>https://yagasoft.com</projectUrl>
Expand All @@ -20,7 +20,8 @@
</dependencies>
<references />
<releaseNotes>
* 1.5.1
* 1.5.2
Added: log execution end attribute
Update: upgraded NuGet packages to latest supported
* 1.4.4
Fixed: validate that the log object is accessible
Expand Down
19 changes: 19 additions & 0 deletions CrmLogger.Fody/ModuleWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class ModuleWeaver
public MethodReference ParamsMethod;
public MethodReference ExceptionMethod;
public MethodReference EndMethod;
public MethodReference EndExecMethod;

public TypeReference String => ModuleDefinition.TypeSystem.String;
public TypeReference Object => ModuleDefinition.TypeSystem.Object;
Expand Down Expand Up @@ -237,6 +238,10 @@ public void Init()
.FindMethod("LogFunctionEnd", "LogEntry", "IExecutionContext", "String", "String", "String", "Int32"));
EndMethod = ModuleDefinition.ImportReference(EndMethod);

EndExecMethod = CommonModuleDefinition.ImportReference(LoggerTypeDefinition
.FindMethod("LogExecutionEndSuccessFlush", "LogEntry", "IExecutionContext", "String", "String", "String", "Int32"));
EndExecMethod = ModuleDefinition.ImportReference(EndExecMethod);

exceptionVariable = new VariableDefinition(ModuleDefinition.ImportReference(ExceptionType));
}

Expand Down Expand Up @@ -366,6 +371,15 @@ private void Inject()

var endInstructions = new List<Instruction>();
endInstructions.AddRange(GetEndInstructions());

var isMethodLogExecEndAttributeExist = Method.CustomAttributes.ContainsAttribute("Yagasoft.Libraries.Common.LogExecEndAttribute");

if (isMethodLogExecEndAttributeExist)
{
LogInfo($">> Method is set to end execution.");
endInstructions.AddRange(GetExecEndInstructions());
}

var finallyInstruction = Instruction.Create(OpCodes.Endfinally);
endInstructions.Add(finallyInstruction);
endInstructions.Reverse();
Expand Down Expand Up @@ -560,6 +574,11 @@ private IEnumerable<Instruction> AddWriteStartEnd(MethodReference writeMethod, b
yield return Instruction.Create(IsInstanceLogger ? OpCodes.Callvirt : OpCodes.Call, writeMethod);
}

private IEnumerable<Instruction> GetExecEndInstructions()
{
return AddWriteStartEnd(EndExecMethod, false);
}

protected List<Instruction> GetReturnValueInstructions(VariableDefinition returnVariable)
{
var instructions = new List<Instruction>();
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Join the chat at https://gitter.im/yagasoft/DynamicsCrm-CrmLogger.Fody](https://badges.gitter.im/yagasoft/DynamicsCrm-CrmLogger.Fody.svg)](https://gitter.im/yagasoft/DynamicsCrm-CrmLogger.Fody?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

### Version: 1.5.1
### Version: 1.5.2
---

NuGet package that extremely simplifies logging function entry, exit, parameter and return values. Used with [DynamicsCrm-CrmLogger](https://github.com/yagasoft/DynamicsCrm-CrmLogger) solution.
Expand Down

0 comments on commit 1d3543d

Please sign in to comment.